|
|
|
|
|
|
|
|
|
|
| import { setDisplayMode } from './presentation-config.js';
|
|
|
| |
| |
| |
|
|
| export class ModeManager {
|
| constructor() {
|
| this.currentMode = 'intro';
|
| this.modes = {
|
| intro: null,
|
| presentation: null,
|
| editor: null
|
| };
|
|
|
|
|
| this.activeSystems = {
|
| smartLayout: false,
|
| dragDrop: false,
|
| contentEditable: false,
|
| resizeObserver: false,
|
| keyboardNav: false,
|
| safeZoneBorder: false
|
| };
|
|
|
|
|
| this.systems = {
|
| smartLayoutControl: null,
|
| dragDropManager: null,
|
| resizeObserver: null,
|
| eventListeners: []
|
| };
|
|
|
| console.log('[ModeManager] Initialized');
|
| }
|
|
|
| |
| |
|
|
| switchMode(newMode) {
|
| if (!['intro', 'presentation', 'editor'].includes(newMode)) {
|
| console.error(`[ModeManager] Invalid mode: ${newMode}`);
|
| return false;
|
| }
|
|
|
| if (this.currentMode === newMode) {
|
| console.log(`[ModeManager] Already in ${newMode} mode`);
|
| return true;
|
| }
|
|
|
| console.log(`[ModeManager] SWITCHING: ${this.currentMode} → ${newMode}`);
|
|
|
|
|
| this.shutdownMode(this.currentMode);
|
|
|
|
|
| this.currentMode = newMode;
|
| setDisplayMode(newMode);
|
|
|
|
|
| this.activateMode(newMode);
|
|
|
|
|
| window.dispatchEvent(new CustomEvent('modeChanged', {
|
| detail: {
|
| mode: newMode,
|
| timestamp: Date.now()
|
| }
|
| }));
|
|
|
| console.log(`[ModeManager] Now in ${newMode} mode (ALL OTHER MODES DISABLED)`);
|
| return true;
|
| }
|
|
|
| |
| |
|
|
| shutdownMode(mode) {
|
| console.log(`[ModeManager] Shutting down ${mode} mode...`);
|
|
|
| switch (mode) {
|
| case 'intro':
|
| this.shutdownIntroMode();
|
| break;
|
| case 'presentation':
|
| this.shutdownPresentationMode();
|
| break;
|
| case 'editor':
|
| this.shutdownEditorMode();
|
| break;
|
| }
|
|
|
| console.log(`[ModeManager] ${mode} mode shut down completely`);
|
| }
|
|
|
| |
| |
|
|
| activateMode(mode) {
|
| console.log(`[ModeManager] Activating ${mode} mode...`);
|
|
|
| switch (mode) {
|
| case 'intro':
|
| this.activateIntroMode();
|
| break;
|
| case 'presentation':
|
| this.activatePresentationMode();
|
| break;
|
| case 'editor':
|
| this.activateEditorMode();
|
| break;
|
| }
|
|
|
| console.log(`[ModeManager] ${mode} mode activated exclusively`);
|
| }
|
|
|
|
|
|
|
|
|
|
|
| activateIntroMode() {
|
|
|
| this.disableAllSystems();
|
|
|
|
|
| if (window.smartLayoutControl) {
|
| window.smartLayoutControl.detach();
|
| }
|
|
|
|
|
| this.hideAllModeUI();
|
|
|
|
|
| const scenes = document.querySelectorAll('[data-scene]');
|
| scenes.forEach(scene => {
|
| if (scene.dataset.scene === 'intro') {
|
| scene.classList.add('active');
|
| } else {
|
| scene.classList.remove('active');
|
| }
|
| });
|
|
|
| console.log('[ModeManager] Intro mode: Static display only (no systems)');
|
| }
|
|
|
| shutdownIntroMode() {
|
|
|
| console.log('[ModeManager] Intro mode: No systems to shutdown');
|
| }
|
|
|
|
|
|
|
|
|
|
|
| activatePresentationMode() {
|
|
|
| this.disableAllSystems();
|
|
|
|
|
| this.activeSystems.keyboardNav = true;
|
|
|
|
|
| this.activeSystems.smartLayout = true;
|
|
|
|
|
| if (window.smartLayoutControl) {
|
| this.systems.smartLayoutControl = window.smartLayoutControl;
|
| window.smartLayoutControl.reattach();
|
| }
|
|
|
|
|
| this.activeSystems.safeZoneBorder = false;
|
|
|
|
|
| this.showPresentationUI();
|
|
|
| console.log('[ModeManager] Presentation mode: Keyboard nav + Smart Layout ENABLED');
|
| }
|
|
|
| shutdownPresentationMode() {
|
|
|
| this.activeSystems.keyboardNav = false;
|
|
|
|
|
| this.activeSystems.smartLayout = false;
|
| if (window.smartLayoutControl) {
|
| window.smartLayoutControl.detach();
|
| }
|
|
|
|
|
| this.hideAllModeUI();
|
|
|
| console.log('[ModeManager] Presentation mode: Shut down');
|
| }
|
|
|
|
|
|
|
|
|
|
|
| activateEditorMode() {
|
|
|
| this.disableAllSystems();
|
|
|
|
|
| this.activeSystems.contentEditable = true;
|
|
|
|
|
| this.activeSystems.dragDrop = true;
|
|
|
|
|
| this.activeSystems.safeZoneBorder = true;
|
| this.showSafeZoneBorder();
|
|
|
|
|
| this.activeSystems.smartLayout = false;
|
| if (window.smartLayoutControl) {
|
| window.smartLayoutControl.detach();
|
| }
|
|
|
|
|
| this.activeSystems.resizeObserver = false;
|
|
|
|
|
| this.showEditorUI();
|
|
|
| console.log('[ModeManager] Editor mode: Edit/Drag only (Smart Layout DISABLED)');
|
| }
|
|
|
| shutdownEditorMode() {
|
|
|
| this.activeSystems.contentEditable = false;
|
| this.disableContentEditable();
|
|
|
|
|
| this.activeSystems.dragDrop = false;
|
|
|
|
|
| this.activeSystems.safeZoneBorder = false;
|
| this.hideSafeZoneBorder();
|
|
|
|
|
| this.hideAllModeUI();
|
|
|
| console.log('[ModeManager] Editor mode: Shut down');
|
| }
|
|
|
|
|
|
|
|
|
|
|
| |
| |
|
|
| disableAllSystems() {
|
|
|
|
|
|
|
| this.disableContentEditable();
|
|
|
|
|
| this.hideSafeZoneBorder();
|
|
|
|
|
| Object.keys(this.activeSystems).forEach(key => {
|
| this.activeSystems[key] = false;
|
| });
|
|
|
| console.log('[ModeManager] All systems disabled (except Smart Layout - handled per mode)');
|
| }
|
|
|
| |
| |
|
|
| disableContentEditable() {
|
| const editables = document.querySelectorAll('[contenteditable="true"]');
|
| editables.forEach(el => {
|
| el.contentEditable = false;
|
| el.blur();
|
| });
|
|
|
|
|
| const stage = document.getElementById('stage');
|
| if (stage) {
|
| stage.classList.remove('slide-editable');
|
| }
|
| }
|
|
|
| |
| |
|
|
| hideSafeZoneBorder() {
|
| const safeZone = document.querySelector('.safe-zone-overlay');
|
| if (safeZone) {
|
| safeZone.classList.add('hidden');
|
| }
|
| }
|
|
|
| |
| |
|
|
| showSafeZoneBorder() {
|
| const safeZone = document.querySelector('.safe-zone-overlay');
|
| if (safeZone) {
|
| safeZone.classList.remove('hidden');
|
| }
|
| }
|
|
|
| |
| |
|
|
| getCurrentMode() {
|
| return this.currentMode;
|
| }
|
|
|
| |
| |
|
|
| isSystemActive(systemName) {
|
| return this.activeSystems[systemName] || false;
|
| }
|
|
|
| |
| |
|
|
| getActiveSystems() {
|
| return Object.entries(this.activeSystems)
|
| .filter(([key, value]) => value)
|
| .map(([key]) => key);
|
| }
|
|
|
| |
| |
|
|
| registerSystem(name, reference) {
|
| this.systems[name] = reference;
|
| console.log(`[ModeManager] Registered system: ${name}`);
|
| }
|
|
|
|
|
|
|
|
|
|
|
| |
| |
|
|
| hideAllModeUI() {
|
|
|
| const navControls = document.getElementById('navControls');
|
| const exitPresentationBtn = document.getElementById('exitPresentationBtn');
|
| const fullscreenBtn = document.getElementById('fullscreenBtn');
|
| const editSlideBtn = document.getElementById('editSlideBtn');
|
|
|
| if (navControls) navControls.classList.add('hidden');
|
| if (exitPresentationBtn) exitPresentationBtn.classList.add('hidden');
|
| if (fullscreenBtn) fullscreenBtn.classList.add('hidden');
|
| if (editSlideBtn) editSlideBtn.classList.add('hidden');
|
|
|
|
|
| const saveSlideBtn = document.getElementById('saveSlideBtn');
|
| const cancelEditBtn = document.getElementById('cancelEditBtn');
|
|
|
| if (saveSlideBtn) saveSlideBtn.classList.add('hidden');
|
| if (cancelEditBtn) cancelEditBtn.classList.add('hidden');
|
|
|
| console.log('[ModeManager] All mode UI hidden');
|
| }
|
|
|
| |
| |
|
|
| showPresentationUI() {
|
| this.hideAllModeUI();
|
|
|
| const navControls = document.getElementById('navControls');
|
| const exitPresentationBtn = document.getElementById('exitPresentationBtn');
|
| const fullscreenBtn = document.getElementById('fullscreenBtn');
|
| const editSlideBtn = document.getElementById('editSlideBtn');
|
|
|
| if (navControls) navControls.classList.remove('hidden');
|
| if (exitPresentationBtn) exitPresentationBtn.classList.remove('hidden');
|
| if (fullscreenBtn) fullscreenBtn.classList.remove('hidden');
|
| if (editSlideBtn) editSlideBtn.classList.remove('hidden');
|
|
|
| console.log('[ModeManager] Presentation UI shown exclusively');
|
| }
|
|
|
| |
| |
|
|
| showEditorUI() {
|
| this.hideAllModeUI();
|
|
|
| const saveSlideBtn = document.getElementById('saveSlideBtn');
|
| const cancelEditBtn = document.getElementById('cancelEditBtn');
|
| const exitPresentationBtn = document.getElementById('exitPresentationBtn');
|
|
|
| if (saveSlideBtn) saveSlideBtn.classList.remove('hidden');
|
| if (cancelEditBtn) cancelEditBtn.classList.remove('hidden');
|
| if (exitPresentationBtn) exitPresentationBtn.classList.remove('hidden');
|
|
|
| console.log('[ModeManager] Editor UI shown exclusively');
|
| }
|
|
|
| |
| |
|
|
| emergencyShutdown() {
|
| console.warn('[ModeManager] EMERGENCY SHUTDOWN');
|
| this.disableAllSystems();
|
|
|
|
|
| if (this.systems.resizeObserver) {
|
| this.systems.resizeObserver.disconnect();
|
| }
|
|
|
|
|
| this.systems.eventListeners.forEach(({ element, event, handler }) => {
|
| element.removeEventListener(event, handler);
|
| });
|
| this.systems.eventListeners = [];
|
|
|
| console.log('[ModeManager] Emergency shutdown complete');
|
| }
|
| }
|
|
|
|
|
| let modeManagerInstance = null;
|
|
|
| |
| |
|
|
| export function getModeManager() {
|
| if (!modeManagerInstance) {
|
| modeManagerInstance = new ModeManager();
|
| }
|
| return modeManagerInstance;
|
| }
|
|
|
| |
| |
|
|
| export function switchToIntroMode() {
|
| return getModeManager().switchMode('intro');
|
| }
|
|
|
| export function switchToPresentationMode() {
|
| return getModeManager().switchMode('presentation');
|
| }
|
|
|
| export function switchToEditorMode() {
|
| return getModeManager().switchMode('editor');
|
| }
|
|
|
| export default ModeManager;
|
|
|