diff --git a/README.md b/README.md index 9c1dcc7..7ee7893 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ note: > You can still check the deprecated alpha version README.md [here](./README.alpha.md). +**Attention: Breaking updates coming soon. Please check [this GitHub issue](https://github.com/0xGG/crossnote/issues/129) for more information.** + https://crossnote.app Crossnote - An interesting markdown note taking progressive web app | Product Hunt Embed diff --git a/package.json b/package.json index 9d4c4af..e6b4e9d 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "automerge": "^0.14.0", "chinese-conv": "^1.0.1", "clsx": "^1.1.0", - "codemirror": "^5.54.0", + "codemirror": "^5.55.0", "crypto-js": "^4.0.0", "date-fns": "^2.12.0", "diff3": "^0.0.3", @@ -69,7 +69,7 @@ "unstated-next": "^1.1.0", "urql": "^1.9.7", "uuid": "^7.0.3", - "vickymd": "^0.2.3" + "vickymd": "^0.2.4" }, "scripts": { "git-info": "echo export default \"{\\\"logMessage\\\": \\\"$(git log -1 --oneline)\\\",\\\"hash\\\":\\\"$(git rev-parse HEAD)\\\"}\" > src/_git_commit.js", diff --git a/src/components/Editor.tsx b/src/components/Editor.tsx index ce10e4d..692dce0 100644 --- a/src/components/Editor.tsx +++ b/src/components/Editor.tsx @@ -71,8 +71,8 @@ import { formatDistance } from "date-fns"; import { getHeaderFromMarkdown } from "../utilities/note"; import { printPreview, - openURL, postprocessPreview as previewPostprocessPreview, + openURL, } from "../utilities/preview"; import ChangeFilePathDialog from "./ChangeFilePathDialog"; import { SettingsContainer } from "../containers/settings"; @@ -644,7 +644,6 @@ export default function Editor(props: Props) { useEffect(() => { if (textAreaElement && !editor && note) { - // console.log("textarea element mounted"); const editor: CodeMirrorEditor = VickyMD.fromTextArea(textAreaElement, { mode: { name: "hypermd", @@ -655,6 +654,17 @@ export default function Editor(props: Props) { keyMap: settingsContainer.keyMap, showCursorWhenSelecting: true, inputStyle: "contenteditable", + hmdClick: (info: any, cm: CodeMirrorEditor) => { + let { text, url } = info; + if (info.type === "link" || info.type === "url") { + const footnoteRef = text.match(/\[[^[\]]+\](?:\[\])?$/); // bare link, footref or [foot][] . assume no escaping char inside + if (!footnoteRef && (info.ctrlKey || info.altKey) && url) { + // just open URL + openURL(url, note); + return false; // Prevent default click event + } + } + }, }); editor.setOption("lineNumbers", false); editor.setOption("foldGutter", false); diff --git a/src/containers/crossnote.ts b/src/containers/crossnote.ts index 78c84d1..424f646 100644 --- a/src/containers/crossnote.ts +++ b/src/containers/crossnote.ts @@ -438,7 +438,6 @@ function useCrossnoteContainer(initialState: InitialState) { } const noteConfig: NoteConfig = { - id: "", tags: tags, modifiedAt: new Date(), createdAt: new Date(), @@ -447,7 +446,7 @@ function useCrossnoteContainer(initialState: InitialState) { const note: Note = { notebook: notebook, filePath: filePath, - markdown: "", + markdown, config: noteConfig, }; setNotebookNotes((notes) => [note, ...notes]); @@ -748,12 +747,29 @@ function useCrossnoteContainer(initialState: InitialState) { const openNoteAtPath = useCallback( (filePath: string) => { if (!crossnote) return; + + if (!filePath.endsWith(".md")) { + filePath += ".md"; + } + const note = notebookNotes.find((n) => n.filePath === filePath); if (note) { _setSelectedNote(note); + } else { + createNewNote( + selectedNotebook, + filePath, + "# " + path.basename(filePath).replace(/\.md$/, ""), + ); } }, - [crossnote, notebookNotes, _setSelectedNote], + [ + crossnote, + notebookNotes, + selectedNotebook, + _setSelectedNote, + createNewNote, + ], ); const loadAttachments = useCallback(async () => { diff --git a/yarn.lock b/yarn.lock index a242074..4328173 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4485,10 +4485,10 @@ code-point-at@^1.0.0: resolved "https://registry.npm.taobao.org/code-point-at/download/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c= -codemirror@^5.54.0: - version "5.54.0" - resolved "https://registry.npm.taobao.org/codemirror/download/codemirror-5.54.0.tgz?cache=0&sync_timestamp=1589962970992&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcodemirror%2Fdownload%2Fcodemirror-5.54.0.tgz#82b6adf662b29eeb7b867fe7839d49e25e4a0b38" - integrity sha1-grat9mKynut7hn/ng51J4l5KCzg= +codemirror@^5.55.0: + version "5.55.0" + resolved "https://registry.npm.taobao.org/codemirror/download/codemirror-5.55.0.tgz?cache=0&sync_timestamp=1592745461049&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcodemirror%2Fdownload%2Fcodemirror-5.55.0.tgz#23731f641288f202a6858fdc878f3149e0e04363" + integrity sha1-I3MfZBKI8gKmhY/ch48xSeDgQ2M= collection-map@^1.0.0: version "1.0.0" @@ -16531,10 +16531,10 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -vickymd@^0.2.3: - version "0.2.3" - resolved "https://registry.npm.taobao.org/vickymd/download/vickymd-0.2.3.tgz#91deaa0632c190309f521a68570cf506bacdc7fc" - integrity sha1-kd6qBjLBkDCfUhpoVwz1BrrNx/w= +vickymd@^0.2.4: + version "0.2.4" + resolved "https://registry.npm.taobao.org/vickymd/download/vickymd-0.2.4.tgz#c011e0c2f74e0f7906b52834460b6f7f68fb7427" + integrity sha1-wBHgwvdOD3kGtSg0Rgtvf2j7dCc= optionalDependencies: echarts "^4.7.0" emojione "^4.5.0"