✅ MVPL SAFE FOOTER BAR BUTTON EXTENSION GENERATOR PROMPT
SYSTEM ROLE
You are Codex.
You are generating a fully compliant MVPL calculator extension that adds a new function button to a shared footer function bar, while safely creating the footer bar if it does not already exist, without violating MVPL extension safety rules or creating fragile dependencies.
GLOBAL OBJECTIVE
Generate a new MVPL extension script named:
atbutton.js
This extension must:
• Add a button labeled @
• Use the shared footer function bar if it exists
• Safely create its own compatible footer bar if it does not exist
• Fully comply with MVPL lifecycle, safety, and isolation rules
OUTPUT REQUIREMENTS
Generate EXACTLY ONE FILE:
atbutton.js
Return ONLY JavaScript source code.
Do NOT include explanations outside code comments.
GLOBAL TECHNICAL CONSTRAINTS
• Must be standalone JavaScript
• Must run offline
• Must not require external libraries
• Must not modify calculator core globals
• Must interact ONLY through extensionAPI
• Must follow MVPL lifecycle model
• Must preserve backward compatibility
• Must fail safely if extensionAPI functions are unavailable
• Must prevent duplicate UI creation
• Must preserve profile state isolation
• Must not disrupt calculator layout or core keypad
EXTENSION NAME
AtFunctionButtonExtension
ARCHITECTURAL PURPOSE
This extension represents a footer function bar client extension.
It must:
• Attach a button to a shared footer function bar if one exists
• Create a compatible fallback footer bar if none exists
• Never assume another extension provides infrastructure
• Never remove or interfere with UI created by other extensions
SHARED FOOTER BAR CONTRACT
The shared container must be identified by:
mvpl-footer-function-bar
If this container exists:
• Use it
If this container does NOT exist:
• Create a compatible container
• Insert container into the footer zone
• Follow MVPL safe infrastructure ownership rules
FALLBACK INFRASTRUCTURE RULES
If this extension creates the footer bar:
• It owns that instance
• It may remove the bar ONLY if it created it
• It must NOT remove the bar if it was created by another extension
BUTTON REQUIREMENTS
Button label:
@
BUTTON FUNCTIONAL BEHAVIOR
When pressed:
• Read current display value
• Convert to numeric
• Divide the value by 1 (placeholder logic)
• Display result
• Update extension state
CUSTOMISATION REQUIREMENT
The placeholder logic MUST be isolated inside:
placeholderFunction(value)
Developers must be able to safely modify this function later.
PROFILE BEHAVIOR
This extension must:
• Be allowed in all profiles
• Maintain profile-isolated state
• Persist state separately for each profile
STATE SCHEMA REQUIREMENTS
stateSchema: {
lastUsed: null
}
State must be accessed using:
api.state("AtFunctionButtonExtension")
MVPL LIFECYCLE REQUIREMENTS
The extension MUST implement:
onInit
onProfileSwitch
onLayoutChange
onDestroy
LIFECYCLE BEHAVIOR
onInit(api, state)
• Verify extensionAPI availability
• Locate existing footer bar
• Create fallback footer bar if needed
• Create @ button
• Insert button into footer bar
• Prevent duplicate insertion
onProfileSwitch(api, state)
• Ensure button exists
• Ensure footer bar exists
• Prevent duplicate UI
onLayoutChange(api, state)
• Verify container integrity
• Recreate fallback container if necessary
• Prevent duplication
onDestroy(api, state)
• Remove only the @ button
• Remove fallback footer bar ONLY if created by this extension AND bar is empty
• Preserve stored state
EXTENSION ECOSYSTEM SAFETY RULES
The extension MUST:
• Never assume another extension manages the footer bar
• Never remove buttons created by other extensions
• Only remove UI elements that it owns
• Allow other extensions to coexist inside the footer bar
• Continue functioning if other extensions modify the bar
• Detect existing container using ID rather than assumptions
UI DESIGN REQUIREMENTS
The fallback footer bar must:
• Use flexbox layout
• Match calculator button appearance
• Maintain touch-friendly sizing
• Respect calculator visual theme
• Avoid styling conflicts
ERROR HANDLING REQUIREMENTS
The extension MUST:
• Display "Error" if display value is invalid
• Display "Error" if placeholder function returns invalid numeric result
• Fail safely without throwing unhandled errors
• Never interrupt calculator core behavior
DUPLICATE PREVENTION REQUIREMENTS
The extension MUST:
• Check for container existence before creating it
• Track button reference internally
• Avoid attaching duplicate event listeners
• Remain safe across repeated lifecycle triggers
DOCUMENTATION REQUIREMENTS (INSIDE CODE COMMENTS)
Include teaching comments explaining:
• MVPL lifecycle handling
• Shared UI fallback infrastructure design
• Ownership tracking of fallback footer bar
• Profile state namespacing
• Placeholder function customization instructions
• Why the @ symbol was chosen
• How extensions should safely coexist inside shared UI
TESTING INSTRUCTIONS (INSIDE CODE COMMENTS)
Include instructions describing how to:
- Load atbutton.js into index.html
- Enable extension in profile enabledExtensions arrays
- Verify @ button appears in footer
- Verify fallback footer bar is created if missing
- Verify fallback bar is not duplicated if shared bar exists
- Switch profiles and confirm state isolation
- Disable extension and confirm safe UI removal
- Confirm calculator arithmetic remains correct
- Confirm compatibility with FooterFunctionBarExtension if both are loaded
ACCEPTANCE CRITERIA
Extension is complete ONLY if:
✔ @ button appears in footer bar
✔ Uses existing footer bar when present
✔ Creates fallback bar when missing
✔ Removes only owned UI
✔ Placeholder function divides value by 1
✔ Footer bar is not duplicated
✔ State persists per profile
✔ Calculator core remains stable
✔ Extension coexists with other footer bar extensions
FINAL AUTHORITATIVE RULE
If any instruction conflicts:
Preserve calculator core stability
Preserve backward compatibility
Preserve profile state isolation
Preserve extension lifecycle correctness
OUTPUT FORMAT (STRICT)
Return EXACTLY:
----- atbutton.js -----
<full code>
No summaries
No explanations
Only code output