|
| 1 | +<script lang="ts"> |
| 2 | + import { lang } from '../../../../../lang/lang'; |
| 3 | + import { HistoryIcon, Redo2 as RedoIcon, Undo2 as UndoIcon } from 'lucide-svelte'; |
| 4 | + import Button from '../../shared/button.svelte'; |
| 5 | + import { historyStore } from '../../../../../stores/document/derived/history-store'; |
| 6 | + import { getView } from '../../context'; |
| 7 | + import { Notice } from 'obsidian'; |
| 8 | + import { LineageView } from 'src/view/view'; |
| 9 | +
|
| 10 | + const view = getView(); |
| 11 | + const history = historyStore(view); |
| 12 | +
|
| 13 | + const isEditing = (view: LineageView) => |
| 14 | + view.viewStore.getValue().document.editing.activeNodeId; |
| 15 | +
|
| 16 | + const toggleSnapshotsModal = () => |
| 17 | + view.viewStore.dispatch({ |
| 18 | + type: 'UI/TOGGLE_HISTORY_SIDEBAR', |
| 19 | + }); |
| 20 | +
|
| 21 | + const selectNextSnapshot = () => { |
| 22 | + if (isEditing(view)) |
| 23 | + new Notice(lang.error_apply_snapshot_while_editing); |
| 24 | + else |
| 25 | + view.documentStore.dispatch({ |
| 26 | + type: 'HISTORY/APPLY_NEXT_SNAPSHOT', |
| 27 | + }); |
| 28 | + }; |
| 29 | +
|
| 30 | + const selectPreviousSnapshot = () => { |
| 31 | + if (isEditing(view)) |
| 32 | + new Notice(lang.error_apply_snapshot_while_editing); |
| 33 | + else |
| 34 | + view.documentStore.dispatch({ |
| 35 | + type: 'HISTORY/APPLY_PREVIOUS_SNAPSHOT', |
| 36 | + }); |
| 37 | + }; |
| 38 | +</script> |
| 39 | + |
| 40 | +<div class="navigation-history buttons-group"> |
| 41 | + <Button |
| 42 | + disabled={$history.items.length === 0} |
| 43 | + label={lang.controls_history} |
| 44 | + on:click={toggleSnapshotsModal} |
| 45 | + tooltipPosition="bottom" |
| 46 | + > |
| 47 | + <HistoryIcon class="svg-icon" size="12" /> |
| 48 | + </Button> |
| 49 | + <Button |
| 50 | + disabled={!$history.state.canGoBack} |
| 51 | + label={lang.controls_history_undo} |
| 52 | + on:click={selectPreviousSnapshot} |
| 53 | + tooltipPosition="bottom" |
| 54 | + > |
| 55 | + <UndoIcon class="svg-icon" size="12" /> |
| 56 | + </Button> |
| 57 | + <Button |
| 58 | + disabled={!$history.state.canGoForward} |
| 59 | + label={lang.controls_history_redo} |
| 60 | + on:click={selectNextSnapshot} |
| 61 | + tooltipPosition="bottom" |
| 62 | + > |
| 63 | + <RedoIcon class="svg-icon" size="12" /> |
| 64 | + </Button> |
| 65 | +</div> |
| 66 | + |
| 67 | +<style> |
| 68 | + .navigation-history { |
| 69 | + display: flex; |
| 70 | + align-items: center; |
| 71 | + justify-content: center; |
| 72 | + } |
| 73 | +</style> |
0 commit comments