diff --git a/src/components/App.vue b/src/components/App.vue index b9683b03..d546834d 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -2,17 +2,17 @@ import { mapState, mapActions } from 'pinia' import { mapWritableState } from 'pinia' - import { useNotesStore } from "../stores/notes-store" + import { useHeynoteStore } from "../stores/heynote-store" import { useErrorStore } from "../stores/error-store" import StatusBar from './StatusBar.vue' import Editor from './Editor.vue' import LanguageSelector from './LanguageSelector.vue' - import NoteSelector from './NoteSelector.vue' + import BufferSelector from './BufferSelector.vue' import Settings from './settings/Settings.vue' import ErrorMessages from './ErrorMessages.vue' - import NewNote from './NewNote.vue' - import EditNote from './EditNote.vue' + import NewBuffer from './NewBuffer.vue' + import EditBuffer from './EditBuffer.vue' export default { components: { @@ -20,10 +20,10 @@ StatusBar, LanguageSelector, Settings, - NoteSelector, + BufferSelector, ErrorMessages, - NewNote, - EditNote, + NewBuffer, + EditBuffer, }, data() { @@ -67,37 +67,37 @@ watch: { // when a dialog is closed, we want to focus the editor showLanguageSelector(value) { this.dialogWatcher(value) }, - showNoteSelector(value) { this.dialogWatcher(value) }, - showCreateNote(value) { this.dialogWatcher(value) }, - showEditNote(value) { this.dialogWatcher(value) }, + showBufferSelector(value) { this.dialogWatcher(value) }, + showCreateBuffer(value) { this.dialogWatcher(value) }, + showEditBuffer(value) { this.dialogWatcher(value) }, - currentNotePath() { + currentBufferPath() { this.focusEditor() }, }, computed: { - ...mapState(useNotesStore, [ - "currentNotePath", + ...mapState(useHeynoteStore, [ + "currentBufferPath", "showLanguageSelector", - "showNoteSelector", - "showCreateNote", - "showEditNote", + "showBufferSelector", + "showCreateBuffer", + "showEditBuffer", ]), editorInert() { - return this.showCreateNote || this.showSettings || this.showEditNote + return this.showCreateBuffer || this.showSettings || this.showEditBuffer }, }, methods: { - ...mapActions(useNotesStore, [ + ...mapActions(useHeynoteStore, [ "openLanguageSelector", - "openNoteSelector", - "openCreateNote", + "openBufferSelector", + "openCreateBuffer", "closeDialog", - "closeNoteSelector", - "openNote", + "closeBufferSelector", + "openBuffer", ]), // Used as a watcher for the booleans that control the visibility of editor dialogs. @@ -177,7 +177,7 @@ - - - diff --git a/src/components/NoteSelector.vue b/src/components/BufferSelector.vue similarity index 94% rename from src/components/NoteSelector.vue rename to src/components/BufferSelector.vue index 9004ca1a..cc4eed6e 100644 --- a/src/components/NoteSelector.vue +++ b/src/components/BufferSelector.vue @@ -4,7 +4,7 @@ import { mapState, mapActions } from 'pinia' import { toRaw } from 'vue'; import { SCRATCH_FILE_NAME } from "../common/constants" - import { useNotesStore } from "../stores/notes-store" + import { useHeynoteStore } from "../stores/heynote-store" export default { data() { @@ -19,7 +19,7 @@ }, async mounted() { - await this.updateNotes() + await this.updateBuffers() this.$refs.container.focus() this.$refs.input.focus() this.buildItems() @@ -29,13 +29,13 @@ }, computed: { - ...mapState(useNotesStore, [ - "notes", - "recentNotePaths", + ...mapState(useHeynoteStore, [ + "buffers", + "recentBufferPaths", ]), orderedItems() { - const sortKeys = Object.fromEntries(this.recentNotePaths.map((item, idx) => [item, idx])) + const sortKeys = Object.fromEntries(this.recentBufferPaths.map((item, idx) => [item, idx])) const getSortScore = (item) => sortKeys[item.path] !== undefined ? sortKeys[item.path] : 1000 const compareFunc = (a, b) => { const sortScore = getSortScore(a) - getSortScore(b) @@ -90,16 +90,16 @@ }, methods: { - ...mapActions(useNotesStore, [ - "updateNotes", - "editNote", - "deleteNote", - "openCreateNote", + ...mapActions(useHeynoteStore, [ + "updateBuffers", + "editBufferMetadata", + "deleteBuffer", + "openCreateBuffer", ]), buildItems() { - //console.log("buildItems", Object.entries(this.notes)) - this.items = Object.entries(this.notes).map(([path, metadata]) => { + //console.log("buildItems", Object.entries(this.buffers)) + this.items = Object.entries(this.buffers).map(([path, metadata]) => { return { "path": path, "name": metadata?.name || path, @@ -158,7 +158,7 @@ event.preventDefault() if (this.actionButton === 1) { //console.log("edit file:", path) - this.editNote(item.path) + this.editBufferMetadata(item.path) } else if (this.actionButton === 2) { this.deleteConfirmNote(item.path) } else { @@ -170,12 +170,12 @@ selectItem(item) { if (item.createNew) { if (this.filteredItems.length === 1) { - this.openCreateNote("new", this.filter) + this.openCreateBuffer("new", this.filter) } else { - this.openCreateNote("new", "") + this.openCreateBuffer("new", "") } } else { - this.$emit("openNote", item.path) + this.$emit("openBuffer", item.path) } }, @@ -220,7 +220,7 @@ async deleteConfirmNote(path) { if (this.deleteConfirm) { //console.log("delete file:", path) - await this.deleteNote(path) + await this.deleteBuffer(path) this.hideActionButtons() this.buildItems() this.selected = Math.min(this.selected, this.items.length - 1) @@ -264,7 +264,7 @@ Edit { @@ -87,8 +87,8 @@ watch: { loadNewEditor() { - //console.log("currentNotePath changed to", path) - this.loadBuffer(this.currentNotePath) + //console.log("currentBufferPath changed to", path) + this.loadBuffer(this.currentBufferPath) }, theme(newTheme) { @@ -150,17 +150,17 @@ }, computed: { - ...mapState(useNotesStore, [ - "currentNotePath", + ...mapState(useHeynoteStore, [ + "currentBufferPath", "libraryId", ]), - ...mapWritableState(useNotesStore, [ + ...mapWritableState(useHeynoteStore, [ "currentEditor", - "currentNoteName", + "currentBufferName", ]), loadNewEditor() { - return `${this.currentNotePath}|${this.libraryId}` + return `${this.currentBufferPath}|${this.libraryId}` }, }, diff --git a/src/components/NewNote.vue b/src/components/NewBuffer.vue similarity index 87% rename from src/components/NewNote.vue rename to src/components/NewBuffer.vue index 8998ae7b..cc0b335a 100644 --- a/src/components/NewNote.vue +++ b/src/components/NewBuffer.vue @@ -2,7 +2,7 @@ import slugify from '@sindresorhus/slugify'; import { mapState, mapActions } from 'pinia' - import { useNotesStore } from "../stores/notes-store" + import { useHeynoteStore } from "../stores/heynote-store" import FolderSelector from './folder-selector/FolderSelector.vue' @@ -24,8 +24,8 @@ }, async mounted() { - if (!!this.createNoteParams.name) { - this.name = this.createNoteParams.name + if (!!this.createBufferParams.name) { + this.name = this.createBufferParams.name this.$refs.nameInput.focus() this.$nextTick(() => { this.$refs.nameInput.select() @@ -34,7 +34,7 @@ this.$refs.nameInput.focus() } - this.updateNotes() + this.updateBuffers() // build directory tree const directories = await window.heynote.buffer.getDirectoryList() @@ -61,7 +61,7 @@ name: part, children: [], path: currentPath, - open: this.currentNotePath.startsWith(currentPath), + open: this.currentBufferPath.startsWith(currentPath), } currentLevel.children.push(node) currentLevel = node @@ -73,14 +73,14 @@ }, computed: { - ...mapState(useNotesStore, [ - "notes", - "currentNotePath", - "createNoteParams", + ...mapState(useHeynoteStore, [ + "buffers", + "currentBufferPath", + "createBufferParams", ]), currentNoteDirectory() { - return this.currentNotePath.split("/").slice(0, -1).join("/") + return this.currentBufferPath.split("/").slice(0, -1).join("/") }, nameInputClass() { @@ -91,15 +91,15 @@ }, dialogTitle() { - return this.createNoteParams.mode === "currentBlock" ? "New Note from Block" : "New Note" + return this.createBufferParams.mode === "currentBlock" ? "New Note from Block" : "New Note" }, }, methods: { - ...mapActions(useNotesStore, [ - "updateNotes", - "createNewNote", - "createNewNoteFromActiveBlock", + ...mapActions(useHeynoteStore, [ + "updateBuffers", + "createNewBuffer", + "createNewBufferFromActiveBlock", ]), onKeydown(event) { @@ -145,23 +145,23 @@ for (let i=0; i<1000; i++) { let filename = slug + ".txt" path = parentPathPrefix + filename - if (!this.notes[path]) { + if (!this.buffers[path]) { break } slug = slugify(this.name + "-" + i) } - if (this.notes[path]) { + if (this.buffers[path]) { console.error("Failed to create note, path already exists", path) this.errors.name = true return } - console.log("Creating note", path) - if (this.createNoteParams.mode === "currentBlock") { - this.createNewNoteFromActiveBlock(path, this.name) - } else if (this.createNoteParams.mode === "new") { - this.createNewNote(path, this.name) + //console.log("Creating note", path, this.createBufferParams) + if (this.createBufferParams.mode === "currentBlock") { + this.createNewBufferFromActiveBlock(path, this.name) + } else if (this.createBufferParams.mode === "new") { + this.createNewBuffer(path, this.name) } else { - throw new Error("Unknown createNote Mode: " + this.createNoteParams.mode) + throw new Error("Unknown createNote Mode: " + this.createBufferParams.mode) } this.$emit("close") diff --git a/src/components/StatusBar.vue b/src/components/StatusBar.vue index 4c7cdefc..170ba09f 100644 --- a/src/components/StatusBar.vue +++ b/src/components/StatusBar.vue @@ -2,7 +2,7 @@ import { mapState } from 'pinia' import UpdateStatusItem from './UpdateStatusItem.vue' import { LANGUAGES } from '../editor/languages.js' - import { useNotesStore } from "../stores/notes-store" + import { useHeynoteStore } from "../stores/heynote-store" const LANGUAGE_MAP = Object.fromEntries(LANGUAGES.map(l => [l.token, l])) const LANGUAGE_NAMES = Object.fromEntries(LANGUAGES.map(l => [l.token, l.name])) @@ -28,8 +28,8 @@ }, computed: { - ...mapState(useNotesStore, [ - "currentNoteName", + ...mapState(useHeynoteStore, [ + "currentBufferName", "currentCursorLine", "currentLanguage", "currentSelectionSize", @@ -84,11 +84,11 @@ - {{ currentNoteName }} + {{ currentBufferName }} { - const notesStore = useNotesStore() + const notesStore = useHeynoteStore() return ViewPlugin.fromClass( class { update(update) { @@ -434,7 +434,7 @@ const emitCursorChange = (editor) => { notesStore.currentSelectionSize = selectionSize notesStore.currentLanguage = block.language.name notesStore.currentLanguageAuto = block.language.auto - notesStore.currentNoteName = editor.name + notesStore.currentBufferName = editor.name } } } diff --git a/src/editor/editor.js b/src/editor/editor.js index 10a6d2bf..85317f68 100644 --- a/src/editor/editor.js +++ b/src/editor/editor.js @@ -23,7 +23,7 @@ import { todoCheckboxPlugin} from "./todo-checkbox.ts" import { links } from "./links.js" import { NoteFormat } from "../common/note-format.js" import { AUTO_SAVE_INTERVAL } from "../common/constants.js" -import { useNotesStore } from "../stores/notes-store.js"; +import { useHeynoteStore } from "../stores/heynote-store.js"; import { useErrorStore } from "../stores/error-store.js"; @@ -67,7 +67,7 @@ export class HeynoteEditor { this.fontTheme = new Compartment this.setDefaultBlockLanguage(defaultBlockToken, defaultBlockAutoDetect) this.contentLoaded = false - this.notesStore = useNotesStore() + this.notesStore = useHeynoteStore() this.errorStore = useErrorStore() this.name = "" @@ -269,40 +269,40 @@ export class HeynoteEditor { this.notesStore.openLanguageSelector() } - openNoteSelector() { - this.notesStore.openNoteSelector() + openBufferSelector() { + this.notesStore.openBufferSelector() } - openCreateNote(createMode) { - this.notesStore.openCreateNote(createMode) + openCreateBuffer(createMode) { + this.notesStore.openCreateBuffer(createMode) } - async createNewNote(path, name) { + async createNewBuffer(path, name) { const data = getBlockDelimiter(this.defaultBlockToken, this.defaultBlockAutoDetect) - await this.notesStore.saveNewNote(path, name, data) + await this.notesStore.saveNewBuffer(path, name, data) // by using requestAnimationFrame we avoid a race condition where rendering the block backgrounds // would fail if we immediately opened the new note (since the block UI wouldn't have time to update // after the block was deleted) requestAnimationFrame(() => { - this.notesStore.openNote(path) + this.notesStore.openBuffer(path) }) } - async createNewNoteFromActiveBlock(path, name) { + async createNewBufferFromActiveBlock(path, name) { const block = getActiveNoteBlock(this.view.state) if (!block) { return } const data = this.view.state.sliceDoc(block.range.from, block.range.to) - await this.notesStore.saveNewNote(path, name, data) + await this.notesStore.saveNewBuffer(path, name, data) deleteBlock(this)(this.view) // by using requestAnimationFrame we avoid a race condition where rendering the block backgrounds // would fail if we immediately opened the new note (since the block UI wouldn't have time to update // after the block was deleted) requestAnimationFrame(() => { - this.notesStore.openNote(path) + this.notesStore.openBuffer(path) }) } diff --git a/src/editor/keymap.js b/src/editor/keymap.js index eb7a229d..15914ef3 100644 --- a/src/editor/keymap.js +++ b/src/editor/keymap.js @@ -58,9 +58,9 @@ export function heynoteKeymap(editor) { ["Alt-ArrowUp", moveLineUp], ["Alt-ArrowDown", moveLineDown], ["Mod-l", () => editor.openLanguageSelector()], - ["Mod-p", () => editor.openNoteSelector()], - ["Mod-s", () => editor.openCreateNote("currentBlock")], - ["Mod-n", () => editor.openCreateNote("new")], + ["Mod-p", () => editor.openBufferSelector()], + ["Mod-s", () => editor.openCreateBuffer("currentBlock")], + ["Mod-n", () => editor.openCreateBuffer("new")], ["Mod-Shift-d", deleteBlock(editor)], ["Alt-Shift-f", formatBlockContent], ["Mod-Alt-ArrowDown", newCursorBelow], diff --git a/src/main.js b/src/main.js index fa49f2bf..dd29cd10 100644 --- a/src/main.js +++ b/src/main.js @@ -6,7 +6,7 @@ import { createPinia } from 'pinia' import App from './components/App.vue' import { loadCurrencies } from './currency' import { useErrorStore } from './stores/error-store' -import { useNotesStore, initNotesStore } from './stores/notes-store' +import { useHeynoteStore, initHeynoteStore } from './stores/heynote-store' import { useEditorCacheStore } from './stores/editor-cache' @@ -26,7 +26,7 @@ window.heynote.getInitErrors().then((errors) => { errors.forEach((e) => errorStore.addError(e)) }) -initNotesStore() +initHeynoteStore() diff --git a/src/stores/notes-store.js b/src/stores/heynote-store.js similarity index 60% rename from src/stores/notes-store.js rename to src/stores/heynote-store.js index 72b6aad9..589d5fc4 100644 --- a/src/stores/notes-store.js +++ b/src/stores/heynote-store.js @@ -5,97 +5,97 @@ import { useEditorCacheStore } from "./editor-cache" import { SCRATCH_FILE_NAME } from "../common/constants" -export const useNotesStore = defineStore("notes", { +export const useHeynoteStore = defineStore("heynote", { state: () => ({ - notes: {}, - recentNotePaths: [SCRATCH_FILE_NAME], + buffers: {}, + recentBufferPaths: [SCRATCH_FILE_NAME], currentEditor: null, - currentNotePath: SCRATCH_FILE_NAME, - currentNoteName: null, + currentBufferPath: SCRATCH_FILE_NAME, + currentBufferName: null, currentLanguage: null, currentLanguageAuto: null, currentCursorLine: null, currentSelectionSize: null, libraryId: 0, - createNoteParams: { + createBufferParams: { mode: "new", nameSuggestion: "" }, - showNoteSelector: false, + showBufferSelector: false, showLanguageSelector: false, - showCreateNote: false, - showEditNote: false, + showCreateBuffer: false, + showEditBuffer: false, }), actions: { - async updateNotes() { - this.setNotes(await window.heynote.buffer.getList()) + async updateBuffers() { + this.setBuffers(await window.heynote.buffer.getList()) }, - setNotes(notes) { - this.notes = notes + setBuffers(buffers) { + this.buffers = buffers }, - openNote(path) { + openBuffer(path) { this.closeDialog() - this.currentNotePath = path + this.currentBufferPath = path - const recent = this.recentNotePaths.filter((p) => p !== path) + const recent = this.recentBufferPaths.filter((p) => p !== path) recent.unshift(path) - this.recentNotePaths = recent.slice(0, 100) + this.recentBufferPaths = recent.slice(0, 100) }, openLanguageSelector() { this.closeDialog() this.showLanguageSelector = true }, - openNoteSelector() { + openBufferSelector() { this.closeDialog() - this.showNoteSelector = true + this.showBufferSelector = true }, - openCreateNote(createMode, nameSuggestion) { + openCreateBuffer(createMode, nameSuggestion) { createMode = createMode || "new" this.closeDialog() - this.createNoteParams = { + this.createBufferParams = { mode: createMode || "new", name: nameSuggestion || "" } - this.showCreateNote = true + this.showCreateBuffer = true }, closeDialog() { - this.showCreateNote = false - this.showNoteSelector = false + this.showCreateBuffer = false + this.showBufferSelector = false this.showLanguageSelector = false - this.showEditNote = false + this.showEditBuffer = false }, - closeNoteSelector() { - this.showNoteSelector = false + closeBufferSelector() { + this.showBufferSelector = false }, - editNote(path) { - if (this.currentNotePath !== path) { - this.openNote(path) + editBufferMetadata(path) { + if (this.currentBufferPath !== path) { + this.openBuffer(path) } this.closeDialog() - this.showEditNote = true + this.showEditBuffer = true }, /** * Create a new note file at `path` with name `name` from the current block of the current open editor, * and switch to it */ - async createNewNoteFromActiveBlock(path, name) { - await toRaw(this.currentEditor).createNewNoteFromActiveBlock(path, name) + async createNewBufferFromActiveBlock(path, name) { + await toRaw(this.currentEditor).createNewBufferFromActiveBlock(path, name) }, /** * Create a new empty note file at `path` with name `name`, and switch to it */ - async createNewNote(path, name) { - await toRaw(this.currentEditor).createNewNote(path, name) + async createNewBuffer(path, name) { + await toRaw(this.currentEditor).createNewBuffer(path, name) }, /** @@ -104,23 +104,20 @@ export const useNotesStore = defineStore("notes", { * @param {*} name Name of the note * @param {*} content Contents (without metadata) */ - async saveNewNote(path, name, content) { - //window.heynote.buffer.save(path, content) - //this.updateNotes() - - if (this.notes[path]) { + async saveNewBuffer(path, name, content) { + if (this.buffers[path]) { throw new Error(`Note already exists: ${path}`) } const note = new NoteFormat() note.content = content note.metadata.name = name - console.log("saving", path, note.serialize()) + //console.log("saving", path, note.serialize()) await window.heynote.buffer.create(path, note.serialize()) - this.updateNotes() + this.updateBuffers() }, - async updateNoteMetadata(path, name, newPath) { + async updateBufferMetadata(path, name, newPath) { const editorCacheStore = useEditorCacheStore() if (this.currentEditor.path !== path) { @@ -133,40 +130,40 @@ export const useNotesStore = defineStore("notes", { //console.log("moving note", path, newPath) editorCacheStore.freeEditor(path) await window.heynote.buffer.move(path, newPath) - this.openNote(newPath) - this.updateNotes() + this.openBuffer(newPath) + this.updateBuffers() } }, - async deleteNote(path) { + async deleteBuffer(path) { if (path === SCRATCH_FILE_NAME) { throw new Error("Can't delete scratch file") } const editorCacheStore = useEditorCacheStore() if (this.currentEditor.path === path) { this.currentEditor = null - this.currentNotePath = SCRATCH_FILE_NAME + this.currentBufferPath = SCRATCH_FILE_NAME } editorCacheStore.freeEditor(path) await window.heynote.buffer.delete(path) - await this.updateNotes() + await this.updateBuffers() }, async reloadLibrary() { const editorCacheStore = useEditorCacheStore() - await this.updateNotes() + await this.updateBuffers() editorCacheStore.clearCache(false) this.currentEditor = null - this.currentNotePath = SCRATCH_FILE_NAME + this.currentBufferPath = SCRATCH_FILE_NAME this.libraryId++ }, }, }) -export async function initNotesStore() { - const notesStore = useNotesStore() +export async function initHeynoteStore() { + const heynoteStore = useHeynoteStore() window.heynote.buffer.setLibraryPathChangeCallback(() => { - notesStore.reloadLibrary() + heynoteStore.reloadLibrary() }) - await notesStore.updateNotes() + await heynoteStore.updateBuffers() }