Skip to content

feat: configurable per-embed multi-format download (SCORM/IMS/HTML5/EPUB) via client-side exporters bundle #32

@erseco

Description

@erseco

Summary

Add an option to expose a split download button on embedded eXeLearning content that lets the visitor download the resource in any of the standard export formats. Which formats are offered is configurable per embed from the block's right-hand sidebar (InspectorControls).

Exports are produced entirely in the browser by reusing the eXeLearning editor's own SharedExporters / exporters.bundle.js (loaded lazily on first click) — no server-side processing, no PHP changes for the actual conversion.

This mirrors the approach already validated in INTEF-Proyectos/procomun#183 (private), which proved the SharedExporters.quickExport() flow against ELPX content.

Motivation

  • Authors today can only link to the raw .elpx, which is not consumable by LMSs or e-readers.
  • Server-side exporting would require running eXeLearning as a service — unnecessary overhead when the bundle already runs client-side.
  • Each embed has different audiences (LMS vs. standalone reader vs. mobile), so format selection must be per-instance, not site-wide.

Supported formats

Format ID Output filename
HTML5 (web) html5 <slug>_web.zip
SCORM 1.2 scorm12 <slug>_scorm.zip
IMS Content Package ims <slug>_ims.zip
EPUB 3 epub3 <slug>.epub

Plus the original .elpx (already exposed today).

UX

Block editor (Gutenberg) — assets/js/elp-upload.js

In InspectorControls, add a new PanelBody "Download options":

  • Toggle: Show download button (default: on).
  • CheckboxControl group: Available formats — one checkbox per format above plus .elpx. All formats checked by default, so new embeds offer the full split menu out of the box. Existing embeds without the attribute fall back to the same default.

Persisted as a new block attribute, e.g.:

```js
downloadFormats: {
type: 'array',
default: ['elpx', 'html5', 'scorm12', 'ims', 'epub3']
}
```

Frontend — public/class-shortcodes.php and block render

Replace the existing single download button with a split button (primary action = first enabled format; dropdown menu = the rest). When only one format is enabled, render as a plain button. When none are enabled, omit the button.

The shortcode gains a `download_formats` attribute (comma-separated) to mirror the block attribute.

Client-side export pipeline

  1. On first download click for a non-`.elpx` format, lazy-load `exporters.bundle.js` (IIFE) from `dist/static/app/yjs/`.
  2. Fetch the extracted `.elpx` content via `/wp-json/exelearning/v1/content/{hash}/...` (already public).
  3. Build the three adapters required by `SharedExporters`:
    • `createDocumentAdapter()`
    • `createResourceFetcher()`
    • `createAssetManager()`
  4. Call `SharedExporters.quickExport(format, { document, resources, assets })`.
  5. Trigger a browser download of the returned blob with the appropriate filename and MIME type.

This logic lives in a new asset (e.g. `assets/js/wp-exe-download.js`), enqueued only when an embed with `downloadFormats` containing a non-`.elpx` entry is rendered.

Sibling module

The same feature lands in `exelearning/omeka-s-exelearning` (separate PR there). Omeka exposes it as a global option in `Module → Settings` because the module has no per-media UI today.

Scope

In scope

  • Block attribute + InspectorControls panel
  • Shortcode attribute parity (`download_formats`)
  • Frontend split-button markup + styles
  • Client-side download script
  • Translatable strings

Out of scope

  • SCORM 2004 (explicitly excluded)
  • HTML5 single-page (explicitly excluded)
  • Server-side export endpoints
  • Caching exported artifacts
  • Changes to the editor submodule itself

Acceptance criteria

  • Block sidebar shows a "Download options" panel with toggles for each format
  • Block attribute and shortcode attribute (`download_formats`) round-trip correctly
  • Frontend renders a split button when 2+ formats are enabled, a plain button when 1, and nothing when 0
  • Downloaded files use the suffix convention: `_web.zip`, `_scorm.zip`, `_ims.zip`, `.epub`, `.elpx`
  • `exporters.bundle.js` is loaded only on first export click, not on page load
  • No server-side export code is added
  • New embeds offer all formats by default

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions