Files
LEDMatrix/web_interface/static/v3/js/widgets/slider.js
T
ChuckandClaude Opus 5.5 7e066174d9 chore: remove dead code, deprecate unused plugin APIs (over-engineering audit)
Whole-tree audit. Every symbol was checked against core, the plugin
monorepo and all eight third-party plugins in plugins.json first.

- Deprecate (removal 3.10.0) plugin-facing methods nothing calls:
  LogoDownloader bulk download, ConfigManager backup/secret wrappers,
  APIHelper extras, BackgroundDataService poll API, PluginManager /
  PluginStateManager info readers, and a few CacheManager, FontManager,
  BaseOddsManager, DynamicTeamResolver methods and PluginTestCase.
  plugin_api_usage.py learns their receiver names; DEPRECATIONS doc
  regenerated.
- Remove core-internal dead code: CacheMetrics, Vegas status/stats
  plumbing, sync "new cycle" message (followers ignore unknown types),
  unused operation types, test-only PluginCatalog readers, IPC to_dict
  and ping, _parse_form_value, CacheStrategyProtocol, ErrorAggregator
  callbacks, duplicate web response helpers.
- Web UI: drop never-mounted json-file-manager.js, the example widget,
  utils/error_handler.js, four uncalled PluginAPI methods, and 29
  escapeHtml shims (call window.LEDEscape directly). Public globals,
  BaseWidget and widget names unchanged.
- Remove six one-off scripts (owner decision) and the unused markupsafe
  and pytest-mock pins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 18:27:40 -04:00

165 lines
6.3 KiB
JavaScript

/**
* LEDMatrix Slider Widget
*
* Range slider with value display and optional tick marks.
*
* Schema example:
* {
* "volume": {
* "type": "number",
* "x-widget": "slider",
* "minimum": 0,
* "maximum": 100,
* "x-options": {
* "step": 5,
* "showValue": true,
* "showMinMax": true,
* "suffix": "%",
* "color": "blue" // "blue", "green", "red", "purple"
* }
* }
* }
*
* @module SliderWidget
*/
(function() {
'use strict';
const base = window.BaseWidget ? new window.BaseWidget('Slider', '1.0.0') : null;
function sanitizeId(id) {
if (base) return base.sanitizeId(id);
return String(id).replace(/[^a-zA-Z0-9_-]/g, '_');
}
function triggerChange(fieldId, value) {
if (base) {
base.triggerChange(fieldId, value);
} else {
const event = new CustomEvent('widget-change', {
detail: { fieldId, value },
bubbles: true,
cancelable: true
});
document.dispatchEvent(event);
}
}
const COLOR_CLASSES = {
blue: 'accent-blue-600',
green: 'accent-green-600',
red: 'accent-red-600',
purple: 'accent-purple-600',
amber: 'accent-amber-500'
};
window.LEDMatrixWidgets.register('slider', {
name: 'Slider Widget',
version: '1.0.0',
render: function(container, config, value, options) {
const fieldId = sanitizeId(options.fieldId || container.id || 'slider');
const xOptions = config['x-options'] || config['x_options'] || {};
const min = config.minimum !== undefined ? config.minimum : (xOptions.min !== undefined ? xOptions.min : 0);
const max = config.maximum !== undefined ? config.maximum : (xOptions.max !== undefined ? xOptions.max : 100);
const step = xOptions.step || 1;
const showValue = xOptions.showValue !== false;
const showMinMax = xOptions.showMinMax !== false;
const suffix = xOptions.suffix || '';
const prefix = xOptions.prefix || '';
const color = xOptions.color || 'blue';
const disabled = xOptions.disabled === true;
const currentValue = value !== null && value !== undefined ? value : min;
const colorClass = COLOR_CLASSES[color] || COLOR_CLASSES.blue;
let html = `<div id="${fieldId}_widget" class="slider-widget" data-field-id="${fieldId}" data-prefix="${window.LEDEscape.attr(prefix)}" data-suffix="${window.LEDEscape.attr(suffix)}">`;
// Value display above slider
if (showValue) {
html += `
<div class="flex justify-center mb-2">
<span id="${fieldId}_value" class="text-lg font-semibold text-gray-700">
${window.LEDEscape.html(prefix)}${window.LEDEscape.html(currentValue)}${window.LEDEscape.html(suffix)}
</span>
</div>
`;
}
// Slider
html += `
<input type="range"
id="${fieldId}_input"
name="${window.LEDEscape.html(options.name || fieldId)}"
value="${window.LEDEscape.attr(currentValue)}"
min="${window.LEDEscape.attr(min)}"
max="${window.LEDEscape.attr(max)}"
step="${window.LEDEscape.attr(step)}"
${disabled ? 'disabled' : ''}
oninput="window.LEDMatrixWidgets.getHandlers('slider').onInput('${fieldId}')"
onchange="window.LEDMatrixWidgets.getHandlers('slider').onChange('${fieldId}')"
class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer ${colorClass} ${disabled ? 'opacity-50 cursor-not-allowed' : ''}">
`;
// Min/Max labels
if (showMinMax) {
html += `
<div class="flex justify-between mt-1">
<span class="text-xs text-gray-400">${window.LEDEscape.html(prefix)}${window.LEDEscape.html(min)}${window.LEDEscape.html(suffix)}</span>
<span class="text-xs text-gray-400">${window.LEDEscape.html(prefix)}${window.LEDEscape.html(max)}${window.LEDEscape.html(suffix)}</span>
</div>
`;
}
html += '</div>';
container.innerHTML = html;
},
getValue: function(fieldId) {
const safeId = sanitizeId(fieldId);
const input = document.getElementById(`${safeId}_input`);
if (!input) return null;
const num = parseFloat(input.value);
return isNaN(num) ? null : num;
},
setValue: function(fieldId, value) {
const safeId = sanitizeId(fieldId);
const input = document.getElementById(`${safeId}_input`);
const valueEl = document.getElementById(`${safeId}_value`);
const widget = document.getElementById(`${safeId}_widget`);
if (input) {
input.value = value !== null && value !== undefined ? value : input.min;
}
if (valueEl && widget && input) {
const prefix = widget.dataset.prefix || '';
const suffix = widget.dataset.suffix || '';
valueEl.textContent = `${prefix}${input.value}${suffix}`;
}
},
handlers: {
onInput: function(fieldId) {
const safeId = sanitizeId(fieldId);
const input = document.getElementById(`${safeId}_input`);
const valueEl = document.getElementById(`${safeId}_value`);
const widget = document.getElementById(`${safeId}_widget`);
if (valueEl && input && widget) {
const prefix = widget.dataset.prefix || '';
const suffix = widget.dataset.suffix || '';
valueEl.textContent = `${prefix}${input.value}${suffix}`;
}
},
onChange: function(fieldId) {
const widget = window.LEDMatrixWidgets.get('slider');
triggerChange(fieldId, widget.getValue(fieldId));
}
}
});
})();