From 6023de29fe05836657599a1b31a646f403d95e9b Mon Sep 17 00:00:00 2001 From: fuwaa Date: Wed, 17 Aug 2022 02:45:23 +0800 Subject: [PATCH] initial commit --- .gitignore | 3 +++ .pre-commit-config.yaml | 5 +++++ CHANGELOG.md | 3 +++ LICENSE.md | 20 +++++++++++++++++++ cz.json | 7 +++++++ keymaps/wordcount.json | 5 +++++ lib/wordcount-message-dialog.js | 35 +++++++++++++++++++++++++++++++++ lib/wordcount.js | 23 ++++++++++++++++++++++ menus/wordcount.json | 26 ++++++++++++++++++++++++ package.json | 13 ++++++++++++ styles/wordcount.less | 2 ++ 11 files changed, 142 insertions(+) create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 CHANGELOG.md create mode 100644 LICENSE.md create mode 100644 cz.json create mode 100644 keymaps/wordcount.json create mode 100644 lib/wordcount-message-dialog.js create mode 100644 lib/wordcount.js create mode 100644 menus/wordcount.json create mode 100644 package.json create mode 100644 styles/wordcount.less diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ade14b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +npm-debug.log +node_modules diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..23af194 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: +- hooks: + - id: commitizen + repo: https://github.com/commitizen-tools/commitizen + rev: v2.29.5 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c3d858c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.1.0 - First Release +* Every feature added +* Every bug fixed diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..8c87916 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,20 @@ +Copyright (c) 2022 + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/cz.json b/cz.json new file mode 100644 index 0000000..e93e6dd --- /dev/null +++ b/cz.json @@ -0,0 +1,7 @@ +{ + "commitizen": { + "name": "cz_conventional_commits", + "version": "0.0.1", + "tag_format": "v0.0.1" + } +} diff --git a/keymaps/wordcount.json b/keymaps/wordcount.json new file mode 100644 index 0000000..09e9ca2 --- /dev/null +++ b/keymaps/wordcount.json @@ -0,0 +1,5 @@ +{ + "body": { + "ctrl-alt-o": "wordcount:toggle" + } +} diff --git a/lib/wordcount-message-dialog.js b/lib/wordcount-message-dialog.js new file mode 100644 index 0000000..4919b52 --- /dev/null +++ b/lib/wordcount-message-dialog.js @@ -0,0 +1,35 @@ +'use babel'; + +import React, { useEffect, useCallback } from 'react' +import { logger, useModal } from 'inkdrop' + +const WordcountMessageDialog = (props) => { + const modal = useModal() + const { Dialog } = inkdrop.components.classes + + const toggle = useCallback(() => { + modal.show() + logger.debug('Wordcount was toggled!') + }, []) + + useEffect(() => { + const sub = inkdrop.commands.add(document.body, { + 'wordcount:toggle': toggle + }) + return () => sub.dispose() + }, [toggle]) + + return ( + + Wordcount + Wordcount was toggled! + + + + + ) +} + +export default WordcountMessageDialog diff --git a/lib/wordcount.js b/lib/wordcount.js new file mode 100644 index 0000000..7f6ed33 --- /dev/null +++ b/lib/wordcount.js @@ -0,0 +1,23 @@ +'use babel'; + +import WordcountMessageDialog from './wordcount-message-dialog'; + +module.exports = { + + activate() { + inkdrop.components.registerClass(WordcountMessageDialog); + inkdrop.layouts.addComponentToLayout( + 'modal', + 'WordcountMessageDialog' + ) + }, + + deactivate() { + inkdrop.layouts.removeComponentFromLayout( + 'modal', + 'WordcountMessageDialog' + ) + inkdrop.components.deleteClass(WordcountMessageDialog); + } + +}; diff --git a/menus/wordcount.json b/menus/wordcount.json new file mode 100644 index 0000000..2d7dce7 --- /dev/null +++ b/menus/wordcount.json @@ -0,0 +1,26 @@ +{ + "context-menu": { + ".CodeMirror": [ + { + "label": "Toggle wordcount", + "command": "wordcount:toggle" + } + ] + }, + "menu": [ + { + "label": "Plugins", + "submenu": [ + { + "label": "wordcount", + "submenu": [ + { + "label": "Toggle", + "command": "wordcount:toggle" + } + ] + } + ] + } + ] +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..02d526b --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "command-palette", + "main": "./lib/wordcount", + "version": "0.0.1", + "description": "A command palette for inkdrop", + "keywords": [], + "repository": "https://github.com/inkdropapp/wordcount", + "license": "MIT", + "engines": { + "inkdrop": "^5.3.1" + }, + "dependencies": {} +} diff --git a/styles/wordcount.less b/styles/wordcount.less new file mode 100644 index 0000000..96fa7ed --- /dev/null +++ b/styles/wordcount.less @@ -0,0 +1,2 @@ +.wordcount { +}