feat: add modal overlay for type definitions

Implement a modal popup system for viewing type definitions without leaving
the current context, with browser-like back/forward navigation.

Modal UI Components:
- Full-screen overlay with centered modal dialog
- Header with title, close button, and navigation controls
- Scrollable content area for type definition
- Back (←) and forward (→) navigation buttons
- Visual disabled state for navigation at history bounds

Navigation Features:
- Click any type reference in root schema to open in modal
- Click type references within modal to navigate deeper
- Keyboard shortcuts: Alt+← (back), Alt+→ (forward), Escape (close)
- History tracking with array and index pointer
- History resets on modal close

JavaScript Implementation:
- `openTypeModal(typeName, addToHistory)`: Open/navigate to type
- `showType(typeName)`: Clone and display type definition content
- `navigateHistory(direction)`: Handle back/forward navigation
- `closeModal()`: Close modal and reset state
- `updateNavButtons()`: Enable/disable nav buttons based on position

CSS Styling (102 lines added):
- `.modal-overlay`: Fixed positioning with semi-transparent background
- `.modal`: Centered container with max dimensions and shadow
- `.modal-header`: Flex layout for nav, title, and close button
- `.modal-nav-btn`: Styled navigation buttons with disabled state
- `.modal-content`: Scrollable content with padding

Identifier Updates:
- Add modal-related IDs and classes to identifiers.rs
- New ID: `modal-overlay`
- New classes: modal, modal-active, modal-header, modal-title, modal-close,
  modal-content, modal-nav, modal-nav-btn, disabled
This commit is contained in:
LGUG2Z committed 2025-12-22 09:31:29 -08:00
1 parent f32d94d929
commit c6835ddbb2
7 files changed
+312 -8

No files matched your search

+134
View File
@@ -1686,4 +1686,138 @@ mod tests {
broken.iter().take(20).collect::<Vec<_>>()
);
}
// Test: Modal has navigation buttons
#[test]
fn test_modal_has_navigation_buttons() {
let generator = Generator::new().unwrap();
let schema = make_schema(json!({
"title": "Test",
"type": "object",
"properties": {
"field": { "type": "string" }
}
}));
let options = Options::default();
let html = generator.generate(&schema, &options).unwrap();
// Should have modal navigation container
assert!(
html.contains("modal-nav"),
"Should have modal-nav container"
);
// Should have back and forward buttons
assert!(
html.contains("data-dir=\"back\""),
"Should have back button"
);
assert!(
html.contains("data-dir=\"forward\""),
"Should have forward button"
);
// Should have navigation button class
assert!(
html.contains("modal-nav-btn"),
"Should have nav button class"
);
}
// Test: Modal nav buttons start disabled
#[test]
fn test_modal_nav_buttons_start_disabled() {
let generator = Generator::new().unwrap();
let schema = make_schema(json!({
"title": "Test",
"type": "object",
"properties": {
"field": { "type": "string" }
}
}));
let options = Options::default();
let html = generator.generate(&schema, &options).unwrap();
// Both nav buttons should start with disabled class
assert!(
html.contains("modal-nav-btn disabled"),
"Nav buttons should start disabled"
);
}
// Test: Modal has keyboard navigation
#[test]
fn test_modal_has_keyboard_navigation() {
let generator = Generator::new().unwrap();
let schema = make_schema(json!({
"title": "Test",
"type": "object",
"properties": {
"field": { "type": "string" }
}
}));
let options = Options::default();
let html = generator.generate(&schema, &options).unwrap();
// Should have Alt+Arrow keyboard handling
assert!(html.contains("altKey"), "Should handle Alt key modifier");
assert!(
html.contains("ArrowLeft"),
"Should handle ArrowLeft for back"
);
assert!(
html.contains("ArrowRight"),
"Should handle ArrowRight for forward"
);
}
// Test: Modal has history management
#[test]
fn test_modal_has_history_management() {
let generator = Generator::new().unwrap();
let schema = make_schema(json!({
"title": "Test",
"type": "object",
"properties": {
"field": { "type": "string" }
}
}));
let options = Options::default();
let html = generator.generate(&schema, &options).unwrap();
// Should have history array and index
assert!(
html.contains("history=[]"),
"Should initialize history array"
);
assert!(
html.contains("historyIndex=-1"),
"Should initialize history index"
);
// Should have navigate function
assert!(
html.contains("navigateHistory"),
"Should have navigateHistory function"
);
}
// Test: Modal history cleared on close
#[test]
fn test_modal_history_cleared_on_close() {
let generator = Generator::new().unwrap();
let schema = make_schema(json!({
"title": "Test",
"type": "object",
"properties": {
"field": { "type": "string" }
}
}));
let options = Options::default();
let html = generator.generate(&schema, &options).unwrap();
// closeModal function should reset history
// The function contains: history=[];historyIndex=-1;
assert!(
html.contains("history=[]") && html.contains("historyIndex=-1"),
"closeModal should reset history state"
);
}
}