Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1ede158
test(layers): add Layer API contract tests and RFC draft
Nov 3, 2026
b16f092
docs(layers): keep GoDAM Central out of the Layer API RFC
Nov 3, 2026
144b51b
ci: run unit tests on PRs into the Layer API base branch
Nov 3, 2026
b8f44b3
Merge pull request #2302 from rtCamp/feature/layer-api-contract-tests
KMchaudhary Nov 3, 2026
9b1fd2d
docs(layers): mark the Layer API RFC accepted
Nov 3, 2026
c0df561
feat(layers): add the Layer API editor registry
Nov 3, 2026
b1f44ed
feat(layers): register form providers as Form layer variations
Nov 4, 2026
fe09175
feat(layers): run video and image layers on one front-end runtime
Nov 4, 2026
abe6c28
feat(layers): register layer types in PHP and render them through cal…
Nov 4, 2026
6914438
feat(layers): clean layers on save, and load layer scripts only where…
Nov 4, 2026
f4cb681
feat(layers): deprecate the old add-on layer hooks behind shims
Nov 4, 2026
2b6afe8
docs(layers): add the Layer API developer guide
Nov 4, 2026
90e95d8
refactor(layers): give each core layer type its own folder, built lik…
Nov 4, 2026
e747f23
chore(layers): note why the core layer loader includes variable paths
Nov 5, 2026
995ce88
feat(layers): give layer.json stylesheets and translations, like bloc…
Nov 5, 2026
b824535
fix(blocks): register the player styles on init so they reach the edi…
Nov 5, 2026
c62035d
Merge pull request #2307 from rtCamp/chore/layer-api-ci
KMchaudhary Nov 6, 2026
6c5404f
Merge pull request #2306 from rtCamp/feature/layer-api-editor-registry
KMchaudhary Nov 6, 2026
f44363a
Merge pull request #2319 from rtCamp/feature/layer-api-form-providers
KMchaudhary Nov 6, 2026
f4b7e00
Merge pull request #2321 from rtCamp/feature/layer-api-frontend-runtime
KMchaudhary Nov 6, 2026
643dd0f
Merge pull request #2322 from rtCamp/feature/layer-api-php-registry
KMchaudhary Nov 6, 2026
57d13da
Merge pull request #2324 from rtCamp/feature/layer-api-php-assets
KMchaudhary Nov 6, 2026
bfa1098
Merge pull request #2325 from rtCamp/feature/layer-api-woo-shims
KMchaudhary Nov 6, 2026
7ddce28
Merge pull request #2327 from rtCamp/feature/layer-api-docs
KMchaudhary Nov 6, 2026
db1c756
Merge pull request #2328 from rtCamp/feature/layer-api-core-folders
KMchaudhary Nov 6, 2026
7a8f9cb
Merge pull request #2331 from rtCamp/feature/layer-api-json-styles-i18n
KMchaudhary Nov 6, 2026
d1b377c
Merge develop into feature/layer-api
Nov 6, 2026
d0fe1a3
Date the Layer API deprecations to 2.8.0
Nov 6, 2026
0be7823
Fix four Layer API review findings
Nov 6, 2026
bc88d8a
Address PR #2345 review feedback
Nov 6, 2026
08a8401
Import Layer API classes and load core layers from RTGODAM_PATH
Nov 11, 2026
ece40c9
Mark the form providers include as reviewed for VIP PHPCS
Nov 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ node_modules/
assets/src/blocks
assets/src/css
assets/src/js
# Core layer types ship from assets/build/layers (layer.json, PHP and built scripts).
assets/src/layers
assets/src/libs/jquery-ui-1.14.2.draggable
.browserslistrc
.eslintignore
Expand Down Expand Up @@ -45,3 +47,6 @@ phpunit.xml.dist

# Dashboard widget sample data: development and review only, never shipped.
/inc/classes/class-dashboard-widget-preview.php

# Design docs and RFCs: for contributors, not shipped.
/docs/
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"env": {
"browser": true
},
"settings": {
// Provided at runtime by the `godam-layers` script (a webpack external).
"import/core-modules": [ "@godam/layers" ]
},
"rules": {
"jsdoc/check-indentation": "error",
"@wordpress/dependency-group": "error"
Expand Down
15 changes: 5 additions & 10 deletions assets/src/blocks/godam-image/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* @var array $attributes Block attributes.
*/

use RTGODAM\Inc\Layers\Layer_Type_Registry;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand Down Expand Up @@ -73,16 +75,9 @@
$godam_meta = get_post_meta( $godam_attachment_id, 'rtgodam_meta', true );
$godam_all_layers = ( is_array( $godam_meta ) && ! empty( $godam_meta['layers'] ) ) ? $godam_meta['layers'] : array();
do_action( 'rtgodam_after_attachment_lookup' );
foreach ( $godam_all_layers as $godam_layer ) {
if ( ! is_array( $godam_layer ) || empty( $godam_layer['type'] ) ) {
continue;
}
if ( 'hotspot' === $godam_layer['type'] && ! empty( $godam_layer['hotspots'] ) ) {
$godam_layers[] = $godam_layer;
} elseif ( 'woo' === $godam_layer['type'] && ! empty( $godam_layer['productHotspots'] ) ) {
$godam_layers[] = $godam_layer;
}
}
// Layers of types that support images and have something to draw
// (`supports.media` and `should_render` in the layer type registry).
$godam_layers = Layer_Type_Registry::get_instance()->filter_layers_for_media( $godam_all_layers, 'image' );
}

// A hotspot link becomes the `href` of a link on the front end, so only http, https
Expand Down
181 changes: 60 additions & 121 deletions assets/src/js/godam-image-layers/render-image-frame.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/**
* GoDAM Image Layers — shared frame renderer.
*
* Draws hotspot and WooCommerce product-hotspot layers onto a single
* `.godam-image__frame` element. Extracted so it can be reused by both the
* Draws the saved layers of one `.godam-image__frame` element. Used by both the
* front-end bootstrap (frontend.js) and the block editor preview (the
* `godam/image` block's edit.js), which renders the same markup into the
* editor canvas and calls this against a ref.
*
* It reuses the existing player-side managers unchanged except for a single
* seam: `manager.computeContentRect` is overridden with an image-box
* implementation (the managers' own version reads a `<video>`, which does not
* exist here). A tiny "media host" adapter satisfies every other manager call
* site; timeline/playback methods are no-ops.
* Layers are mounted through the Layer API runtimes (#2294), exactly as on a
* video, on a host whose media is the image. Only runtimes that declare
* `supports.media: [ 'image' ]` run here (core: Hotspot, from its view script
* `assets/build/layers/hotspot/view.js`; add-ons such as the Woo layer). A tiny "media host" adapter stands in for the
* Video.js player; timeline and playback methods are no-ops.
*
* Note: importing this module is NOT side-effect-free — it initializes
* `window.godamLayerRegistry` (see the layer-registry-init import below). It
Expand All @@ -25,9 +24,9 @@
// Side-effect import: creates window.godamLayerRegistry and drains the queue the
// Woo front-end script pushed to (image-only pages never boot the video player).
import './../godam-player/utils/layer-registry-init.js';
import HotspotLayerManager from './../godam-player/managers/layers/hotspotLayerManager.js';
import { loadFontAwesome, hasHotspotsWithIcons, renderFontAwesomeIcons } from './../godam-player/utils/pluginLoader.js';
import { resolveHotspotStyle } from './../godam-player/utils/hotspotStyle.js';
import { createLayerHost } from './../godam-layers/runtime/host.js';
import { layersUseIconFont, getLayerRuntime, whenLayerRuntime, runtimeUsesIconFont } from './../godam-layers/runtime/registry.js';
import { loadFontAwesome, renderFontAwesomeIcons } from './../godam-player/utils/pluginLoader.js';

/**
* Build a minimal "media host" adapter for the layer managers.
Expand Down Expand Up @@ -111,8 +110,6 @@ export function initImageFrame( frame ) {
}

const instanceId = frame.dataset.instanceId || '';
const hotspotLayers = layers.filter( ( layer ) => layer?.type === 'hotspot' );
const wooLayers = layers.filter( ( layer ) => layer?.type === 'woo' );
const adapter = makeImageAdapter( frame, img );

// Everything that must be undone on teardown — resize listener, ResizeObserver
Expand Down Expand Up @@ -148,120 +145,62 @@ export function initImageFrame( frame ) {
return;
}

let hotspotManager = null;
let wooManager = null;

try {
// Two `display:contents` group wrappers inside the SINGLE overlay. They
// carry no box and form no stacking context, so all markers share the one
// overlay's stacking context (the z-index fix), while giving each manager a
// private scope for its index-based `.hotspot` reposition queries — hotspot
// and Woo markers both use the `.hotspot` class, so they must not share a
// query root.
const hotspotGroup = document.createElement( 'div' );
hotspotGroup.className = 'godam-image-hotspot-group';
hotspotGroup.style.display = 'contents';
const wooGroup = document.createElement( 'div' );
wooGroup.className = 'godam-image-woo-group';
wooGroup.style.display = 'contents';
sharedEl.appendChild( hotspotGroup );
sharedEl.appendChild( wooGroup );
const host = createLayerHost( {
player: adapter,
media: { type: 'image', element: img },
instanceId,
} );
cleanups.push( () => host.destroy() );

// One `display:contents` wrapper per layer inside the SINGLE overlay.
// They carry no box and form no stacking context, so every marker
// shares the one overlay's stacking context (the z-index fix) and
// absolute markers resolve against the positioned frame, while each
// layer gets a private scope for its manager's index-based `.hotspot`
// reposition queries.
const mountLayer = ( layer, runtime ) => {
const layerEl = document.createElement( 'div' );
layerEl.className = 'godam-image-layer-item';
layerEl.dataset.layerType = String( layer?.type || '' );
layerEl.style.display = 'contents';
sharedEl.appendChild( layerEl );
if ( ! host.mount( layer, layerEl, runtime ) ) {
layerEl.remove();
}
};

// Merge every hotspot layer into ONE manager layer object so the manager's
// index-based reposition stays consistent. Per-layer style is flattened
// onto each hotspot (legacy per-hotspot fields) so distinct layer colours /
// icons survive the merge.
if ( hotspotLayers.length ) {
const mergedHotspots = [];
hotspotLayers.forEach( ( layer ) => {
( layer.hotspots || [] ).forEach( ( hotspot ) => {
const style = resolveHotspotStyle( layer, hotspot );
// Button-style hotspots keep their own button fields; tag them so
// the style-less merged layer still renders them as buttons.
if ( style.styleType === 'button' ) {
mergedHotspots.push( { ...hotspot, styleType: 'button' } );
layers.forEach( ( layer ) => {
const runtime = getLayerRuntime( layer?.type );
if ( runtime ) {
mountLayer( layer, runtime );
return;
}
// Its view script may still load (deferred or delayed): mount it then.
const stop = whenLayerRuntime( layer?.type, ( lateRuntime ) => {
const mountLate = () => {
if ( torn ) {
return;
}
mergedHotspots.push( {
...hotspot,
icon: style.icon || '',
customIconUrl: style.customIconUrl || null,
backgroundColor: style.color,
} );
} );
} );
const mergedLayer = {
id: 'godam-image-hotspots',
type: 'hotspot',
pauseOnHover: false,
hotspots: mergedHotspots,
};
hotspotManager = new HotspotLayerManager( adapter, {}, instanceId );
hotspotManager.computeContentRect = () => adapter.computeContentRect();
hotspotManager.setupHotspotLayer( mergedLayer, hotspotGroup );
const layerObj = hotspotManager.hotspotLayers[ hotspotManager.hotspotLayers.length - 1 ];
// The analytics runtime is loaded on image pages now (see
// godam-image/render.php), so plain-hotspot interaction emits are
// captured like on video. Commerce impressions (Top Products) come from
// the Woo layer's parent 'viewed' below; a plain hotspot has no product
// row, so no impression beacon is fired here.
hotspotManager.createHotspots( layerObj );
}

// Woo layers — resolved from the shared registry (present only when the
// godam-for-woo add-on is active). Each layer is set up INDIVIDUALLY on
// its own container rather than merged into one: the Woo manager resolves
// every marker's style (pulse / icon / custom icon + colours), behaviour
// (clickBehaviour, tooltipDisplay, pauseOnHover) and analytics id from that
// layer's own config, and its resize reposition queries `.hotspot` by index
// WITHIN each layer's element against that layer's productHotspots. Merging
// (the old behaviour) forced every product to inherit the first layer's
// style/id, so a second layer's custom icon rendered as the first layer's
// pulse. A single shared manager instance keeps the product cache/prefetch
// shared across layers.
if ( wooLayers.length ) {
const WooManager = window.godamLayerRegistry?.getLayerManager?.( 'woo' );
if ( WooManager ) {
wooManager = new WooManager( adapter, {}, instanceId );
wooManager.computeContentRect = () => adapter.computeContentRect();
wooLayers.forEach( ( layer ) => {
// A per-layer `display:contents` wrapper: it carries no box and
// forms no stacking context, so all markers still share the ONE
// overlay's stacking context (the z-index fix) and absolute
// markers resolve against the positioned `.godam-image__frame`,
// while giving each layer a private scope for the manager's
// index-based `.hotspot` reposition queries.
const layerEl = document.createElement( 'div' );
layerEl.className = 'godam-image-woo-layer';
layerEl.style.display = 'contents';
wooGroup.appendChild( layerEl );
wooManager.setupLayer( layer, layerEl );
const layerObj = wooManager.wooLayers[ wooManager.wooLayers.length - 1 ];
wooManager.createProductHotspots( layerObj );
// A still image has no play/visibility transition, so fire the
// parent-layer 'viewed' impression beacon once, now, on render.
// This is the impressions signal the product rollup reads; without
// it image Woo hotspots would always show 0 impressions. Guarded
// no-op until the analytics runtime is loaded (it is a dependency
// of this script, so it is present by now).
if ( typeof wooManager.emitLayerVisible === 'function' ) {
wooManager.emitLayerVisible( layerObj.layer );
mountLayer( layer, lateRuntime );
if ( runtimeUsesIconFont( lateRuntime, layer ) ) {
renderFontAwesomeIcons( frame );
}
} );
}
}
};
if ( runtimeUsesIconFont( lateRuntime, layer ) ) {
loadFontAwesome().then( mountLate ).catch( mountLate );
} else {
mountLate();
}
} );
cleanups.push( stop );
} );
host.dispatch( 'onReady' );

// Reposition markers when the rendered image box changes. The listener
// and observer are registered for teardown so redraws / unmounts in the
// editor don't accumulate them (and don't pin a detached <img>).
const reposition = () => {
if ( hotspotManager && typeof hotspotManager.updateHotspotPositions === 'function' ) {
hotspotManager.updateHotspotPositions();
}
if ( wooManager && typeof wooManager.updateProductHotspotPositions === 'function' ) {
wooManager.updateProductHotspotPositions();
}
};
const reposition = () => host.dispatch( 'onResize' );
window.addEventListener( 'resize', reposition );
cleanups.push( () => window.removeEventListener( 'resize', reposition ) );
if ( 'ResizeObserver' in window ) {
Expand All @@ -274,11 +213,11 @@ export function initImageFrame( frame ) {
// frame's document. In the block-editor iframe the global FA observer
// never sees these nodes, so icon hotspots would otherwise render as
// empty boxes; on the front end this is a harmless idempotent pass.
if ( hasHotspotsWithIcons( layers ) ) {
if ( layersUseIconFont( layers ) ) {
renderFontAwesomeIcons( frame );

// Woo markers are appended asynchronously (createProductHotspots
// resolves the products over REST first), so the pass above runs
// Some markers are appended asynchronously (the Woo layer resolves
// its products over REST first), so the pass above runs
// before their `<i class="fa-solid ...">` nodes even exist. On the
// front end FontAwesome's own dom.watch() observer catches them
// late; inside the editor iframe it never does, leaving Woo product
Expand Down Expand Up @@ -313,7 +252,7 @@ export function initImageFrame( frame ) {
const start = () => {
// Load FontAwesome first when any hotspot uses an icon style, else the
// icon glyphs render as empty boxes.
if ( hasHotspotsWithIcons( layers ) ) {
if ( layersUseIconFont( layers ) ) {
loadFontAwesome().then( render ).catch( render );
} else {
render();
Expand Down
Loading
Loading