1import { timeDaysValue, timeHoursValue, timeMinsValue, timeDaysUnit, timeHoursUnit, timeMinsUnit } from 'constants/containers'; 2 3// Function to validate and format input 4function validateTimeInput(value) { 5 // Remove any non-numeric characters 6 value = value.replace(/[^0-9]/g, ''); 7 8 // Convert to number and ensure it's not negative 9 let num = Math.max(0, parseInt(value) || 0); 10 11 // For hours and minutes, cap at 59 12 if (value !== timeDaysValue().textContent) { 13 num = Math.min(num, 59); 14 } 15 16 return num.toString(); 17} 18 19// Function to update unit labels (singular/plural) 20function updateUnitLabel(value, unit) { 21 const num = parseInt(value) || 0; 22 if (unit === timeDaysUnit()) { 23 unit.textContent = num === 1 ? 'day' : 'days'; 24 } else if (unit === timeHoursUnit()) { 25 unit.textContent = num === 1 ? 'hour' : 'hours'; 26 } else if (unit === timeMinsUnit()) { 27 unit.textContent = num === 1 ? 'minute' : 'minutes'; 28 } 29} 30 31// Function to handle input events 32export function handleTimeInput(event) { 33 const element = event.target; 34 const oldValue = element.textContent; 35 36 // Don't process if the content is the skeleton loader 37 if (element.querySelector('.time-skeleton-loader')) { 38 return; 39 } 40 41 // Get corresponding unit element 42 let unitElement; 43 if (element === timeDaysValue()) unitElement = timeDaysUnit(); 44 else if (element === timeHoursValue()) unitElement = timeHoursUnit(); 45 else if (element === timeMinsValue()) unitElement = timeMinsUnit(); 46 47 // Validate and format the input 48 const newValue = validateTimeInput(element.textContent); 49 50 // Only update if value changed 51 if (newValue !== oldValue) { 52 element.textContent = newValue; 53 updateUnitLabel(newValue, unitElement); 54 } 55} 56 57// Function to handle focus events 58export function handleTimeFocus(event) { 59 const element = event.target; 60 61 // If there's a skeleton loader, clear it 62 const skeleton = element.querySelector('.time-skeleton-loader'); 63 if (skeleton) { 64 skeleton.remove(); 65 element.textContent = '0'; 66 } 67 68 // Select all text when focused 69 const selection = window.getSelection(); 70 const range = document.createRange(); 71 range.selectNodeContents(element); 72 selection.removeAllRanges(); 73 selection.addRange(range); 74} 75 76// Function to handle blur events 77export function handleTimeBlur(event) { 78 const element = event.target; 79 80 // Ensure empty fields show 0 81 if (!element.textContent.trim()) { 82 element.textContent = '0'; 83 } 84}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.