Files
crank/apps/ui/js/slot-registry.js
T
github-ops 0af60b1693
CI / Rust Checks (push) Failing after 2m6s
CI / UI Checks (push) Has been skipped
CI / Frontend E2E (push) Has been skipped
CI / Deployment Manifests (push) Has been skipped
Deploy / deploy (push) Successful in 2m26s
Remove enterprise leftovers from community
2026-06-20 12:04:46 +00:00

46 lines
1017 B
JavaScript

(function() {
var allowedSlots = {};
var handlers = Object.create(null);
function noop() {}
function isAllowed(slotId) {
return !!allowedSlots[slotId];
}
function register(slotId, render) {
if (!isAllowed(slotId) || typeof render !== 'function') {
return false;
}
handlers[slotId] = render;
return true;
}
function renderInto(target, slotId, context) {
if (!(target && slotId && isAllowed(slotId))) {
return;
}
var handler = handlers[slotId] || noop;
handler(target, context || {});
}
function renderAll(root, context) {
var scope = root || document;
scope.querySelectorAll('[data-slot]').forEach(function(target) {
renderInto(target, target.getAttribute('data-slot'), context);
});
}
function knownSlots() {
return Object.keys(allowedSlots);
}
window.CrankUiSlots = {
isAllowed: isAllowed,
knownSlots: knownSlots,
register: register,
renderAll: renderAll,
renderInto: renderInto,
};
}());