diff options
| author | elioat <elioat@tilde.institute> | 2025-09-30 21:23:06 -0400 |
|---|---|---|
| committer | elioat <elioat@tilde.institute> | 2025-09-30 21:23:06 -0400 |
| commit | 42a0fd947337fea48a0313090c427265f7ac6790 (patch) | |
| tree | 3dd10d583341773fc9d72140dc66e8b6663a947b /html | |
| parent | 708c3b38e9814def94b242b6ef432bdb6fbf0626 (diff) | |
| download | tour-42a0fd947337fea48a0313090c427265f7ac6790.tar.gz | |
*
Diffstat (limited to 'html')
| -rw-r--r-- | html/notebook/index.html | 161 |
1 files changed, 139 insertions, 22 deletions
diff --git a/html/notebook/index.html b/html/notebook/index.html index 9ad3068..bf322d3 100644 --- a/html/notebook/index.html +++ b/html/notebook/index.html @@ -23,6 +23,10 @@ border-bottom: 1px solid #8888cc; display: flex; gap: 8px; + align-items: center; + } + .toolbar-spacer { + flex: 1; } button { background: #8888cc; @@ -34,6 +38,10 @@ font-size: 16px; } button:hover { background: #aaaaee; } + button:disabled { + opacity: 0.4; + cursor: not-allowed; + } #container { flex: 1; overflow-y: auto; @@ -63,6 +71,10 @@ font-family: Georgia, serif; } .cell-input:focus { outline: 1px solid #8888cc; } + .cell.collapsed .cell-input, + .cell.collapsed .cell-output { + display: none; + } .cell-toolbar { background: #aaaaee; padding: 6px 10px; @@ -113,47 +125,89 @@ /* Dark mode */ @media (prefers-color-scheme: dark) { - body { + body:not(.light-mode) { background: #1e1e1e; color: #d4d4d4; } - #toolbar { + body:not(.light-mode) #toolbar { background: #252526; border-bottom: 1px solid #3e3e42; } - button { + body:not(.light-mode) button { background: #0e639c; color: white; border: none; } - button:hover { background: #1177bb; } - .cell { + body:not(.light-mode) button:hover { background: #1177bb; } + body:not(.light-mode) .cell { border: 1px solid #3e3e42; background: #252526; } - .cell-input { + body:not(.light-mode) .cell-input { background: #1e1e1e; color: #d4d4d4; } - .cell-input:focus { outline: 1px solid #0e639c; } - .cell-toolbar { + body:not(.light-mode) .cell-input:focus { outline: 1px solid #0e639c; } + body:not(.light-mode) .cell-toolbar { background: #2d2d30; } - .cell-type { + body:not(.light-mode) .cell-type { color: #858585; } - .cell-output { + body:not(.light-mode) .cell-output { background: #1e1e1e; border-top: 1px solid #3e3e42; } - .output-result { color: #4ec9b0; } - .output-error { color: #f48771; } - .output-log { color: #d4d4d4; } - .output-scope { + body:not(.light-mode) .output-result { color: #4ec9b0; } + body:not(.light-mode) .output-error { color: #f48771; } + body:not(.light-mode) .output-log { color: #d4d4d4; } + body:not(.light-mode) .output-scope { color: #858585; border-top: 1px solid #3e3e42; } } + + /* Force dark mode when class is set */ + body.dark-mode { + background: #1e1e1e; + color: #d4d4d4; + } + body.dark-mode #toolbar { + background: #252526; + border-bottom: 1px solid #3e3e42; + } + body.dark-mode button { + background: #0e639c; + color: white; + border: none; + } + body.dark-mode button:hover { background: #1177bb; } + body.dark-mode .cell { + border: 1px solid #3e3e42; + background: #252526; + } + body.dark-mode .cell-input { + background: #1e1e1e; + color: #d4d4d4; + } + body.dark-mode .cell-input:focus { outline: 1px solid #0e639c; } + body.dark-mode .cell-toolbar { + background: #2d2d30; + } + body.dark-mode .cell-type { + color: #858585; + } + body.dark-mode .cell-output { + background: #1e1e1e; + border-top: 1px solid #3e3e42; + } + body.dark-mode .output-result { color: #4ec9b0; } + body.dark-mode .output-error { color: #f48771; } + body.dark-mode .output-log { color: #d4d4d4; } + body.dark-mode .output-scope { + color: #858585; + border-top: 1px solid #3e3e42; + } </style> </head> <body> @@ -164,6 +218,7 @@ <script id="app-code"> const STORAGE_KEY = 'notebook-state-v1'; +const THEME_KEY = 'notebook-theme-v1'; const notebookScope = {}; @@ -197,6 +252,46 @@ function saveToLocalStorage(state) { } } +function loadTheme() { + const saved = localStorage.getItem(THEME_KEY); + if (saved) { + return saved; + } + return 'auto'; +} + +function saveTheme(theme) { + try { + localStorage.setItem(THEME_KEY, theme); + } catch (e) { + console.error('Failed to save theme:', e); + } +} + +function applyTheme(theme) { + document.body.classList.remove('light-mode', 'dark-mode'); + if (theme === 'light') { + document.body.classList.add('light-mode'); + } else if (theme === 'dark') { + document.body.classList.add('dark-mode'); + } +} + +function toggleTheme() { + const current = loadTheme(); + let next; + if (current === 'auto') { + next = 'light'; + } else if (current === 'light') { + next = 'dark'; + } else { + next = 'auto'; + } + saveTheme(next); + applyTheme(next); + return next; +} + function executeInNotebook(code) { const logs = []; const capturedConsole = { @@ -245,7 +340,8 @@ function update(state, action) { id: state.nextId, type: action.cellType, content: '', - output: null + output: null, + collapsed: false }]), nextId: state.nextId + 1 }; @@ -342,6 +438,23 @@ function update(state, action) { } break; + case 'TOGGLE_COLLAPSE': + newState = { + cells: state.cells.map(function(c) { + return c.id === action.id + ? Object.assign({}, c, {collapsed: !c.collapsed}) + : c; + }), + nextId: state.nextId + }; + break; + + case 'TOGGLE_THEME': + toggleTheme(); + newState = state; + shouldRender = false; + break; + case 'EXPORT': exportNotebook(state); newState = state; @@ -367,7 +480,7 @@ function update(state, action) { function view(state) { return state.cells.map(function(cell, index) { - let html = '<div class="cell" data-type="' + cell.type + '">'; + let html = '<div class="cell' + (cell.collapsed ? ' collapsed' : '') + '" data-type="' + cell.type + '">'; html += '<div class="cell-toolbar">'; html += '<div class="cell-toolbar-left">'; html += '<span class="cell-type">' + cell.type + '</span>'; @@ -380,12 +493,11 @@ function view(state) { html += '<button onclick="app.dispatch({type: \'DELETE_CELL\', id: ' + cell.id + '})">Delete</button>'; html += '</div>'; html += '<div class="cell-toolbar-right">'; - if (index > 0) { - html += '<button onclick="app.dispatch({type: \'MOVE_CELL_UP\', id: ' + cell.id + '})">↑</button>'; - } - if (index < state.cells.length - 1) { - html += '<button onclick="app.dispatch({type: \'MOVE_CELL_DOWN\', id: ' + cell.id + '})">↓</button>'; - } + html += '<button onclick="app.dispatch({type: \'TOGGLE_COLLAPSE\', id: ' + cell.id + '})">' + (cell.collapsed ? '▼' : '▲') + '</button>'; + const upDisabled = index === 0 ? ' disabled' : ''; + const downDisabled = index === state.cells.length - 1 ? ' disabled' : ''; + html += '<button' + upDisabled + ' onclick="app.dispatch({type: \'MOVE_CELL_UP\', id: ' + cell.id + '})">↑</button>'; + html += '<button' + downDisabled + ' onclick="app.dispatch({type: \'MOVE_CELL_DOWN\', id: ' + cell.id + '})">↓</button>'; html += '</div>'; html += '</div>'; html += '<textarea class="cell-input" data-cell-id="' + cell.id + '" oninput="app.autoResize(this); app.dispatch({type: \'UPDATE_CELL\', id: ' + cell.id + ', content: this.value});" onkeydown="if(event.key===\'Enter\' && (event.metaKey||event.ctrlKey) && ' + (cell.type === 'code') + ') { event.preventDefault(); app.dispatch({type: \'EXECUTE_CELL\', id: ' + cell.id + '}); }">' + escapeHtml(cell.content) + '</textarea>'; @@ -505,6 +617,8 @@ function getHtmlTemplate() { ' <button onclick="app.dispatch({type: \'EXPORT\'})">Export</button>\n' + ' <button onclick="app.dispatch({type: \'EXPORT_TEXT\'})">Export Text</button>\n' + ' <button onclick="app.dispatch({type: \'EXPORT_CODE\'})">Export Code</button>\n' + + ' <div class="toolbar-spacer"></div>\n' + + ' <button onclick="app.dispatch({type: \'TOGGLE_THEME\'})">Toggle Theme</button>\n' + '</div>\n\n' + '<div id="container"></div>\n\n' + '</body>\n' + @@ -587,6 +701,7 @@ const app = { window.app = app; document.addEventListener('DOMContentLoaded', function() { + applyTheme(loadTheme()); render(app.state); }); </script> @@ -597,6 +712,8 @@ document.addEventListener('DOMContentLoaded', function() { <button onclick="app.dispatch({type: 'EXPORT'})">Export</button> <button onclick="app.dispatch({type: 'EXPORT_TEXT'})">Export Text</button> <button onclick="app.dispatch({type: 'EXPORT_CODE'})">Export Code</button> + <div class="toolbar-spacer"></div> + <button onclick="app.dispatch({type: 'TOGGLE_THEME'})">Toggle Theme</button> </div> <div id="container"></div> |