Skip to content

Commit

Permalink
Lots of clean up, some style changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan McQuen <[email protected]>
  • Loading branch information
ryanpcmcquen committed Jan 3, 2021
1 parent abbb992 commit db29472
Show file tree
Hide file tree
Showing 8 changed files with 3,131 additions and 3,944 deletions.
14 changes: 7 additions & 7 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"presets": [
["env", { "targets": { "node": "current" } }],
"@babel/preset-typescript",
"@babel/preset-react",
[
"@babel/preset-env",
{
"targets": {
"electron": "7.3.2",
"node": 14
"node": 12
}
}
],



],
"plugins": [
[
Expand All @@ -35,7 +34,8 @@
]
}
],
"@babel/plugin-proposal-class-properties"
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-object-rest-spread"
],
"sourceMaps": true
}
}
25 changes: 12 additions & 13 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@

root: true
parser: '@typescript-eslint/parser'
parser: "@typescript-eslint/parser"
parserOptions:
sourceType: 'module'
sourceType: "module"
env:
browser: true
browser: true
plugins:
- '@typescript-eslint'
- "@typescript-eslint"
extends:
- 'plugin:@typescript-eslint/recommended'
- 'plugin:prettier/recommended'
- 'prettier/@typescript-eslint'
- "plugin:@typescript-eslint/recommended"
- "plugin:prettier/recommended"
- "prettier/@typescript-eslint"
rules:
'@typescript-eslint/no-unused-vars':
- 'error'
- ignoreRestSiblings: true
argsIgnorePattern: '^_'
'@typescript-eslint/no-explicit-any': 'error'
"@typescript-eslint/no-unused-vars":
- "error"
- ignoreRestSiblings: true
argsIgnorePattern: "^_"
"@typescript-eslint/no-explicit-any": "error"
42 changes: 22 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wiki_links",
"main": "./lib/index",
"version": "0.1.14",
"version": "0.2.0",
"description": "Bring wiki style links to Inkdrop.",
"keywords": [],
"repository": "https://github.com/ryanpcmcquen/inkdrop_wiki_links.git",
Expand All @@ -10,31 +10,33 @@
"wiki_link.less"
],
"scripts": {
"build": "babel src/ -d lib/",
"dev": "babel src/ -s -d lib/ --watch"
"build": "babel src/ -s --extensions .js,.jsx,.ts,.tsx -d lib/",
"build-broken": "babel src/ -s --extensions '.js,.jsx,.ts,.tsx' -d lib/",
"dev": "babel src/ -s --extensions .js,.jsx,.ts,.tsx -d lib/ --watch"
},
"engines": {
"inkdrop": "^5.x"
},
"dependencies": {
"@textcomplete/codemirror": "0.x.x",
"@textcomplete/core": "0.x.x"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.0",
"@babel/plugin-proposal-class-properties": "7.12.1",
"@babel/cli": "7.x.x",
"@babel/core": "7.x.x",
"@babel/plugin-proposal-class-properties": "7.x.x",
"@babel/plugin-proposal-object-rest-spread": "7.x.x",
"@babel/preset-env": "7.x.x",
"@babel/preset-react": "7.x.x",
"@babel/preset-typescript": "^7.12.7",
"@textcomplete/codemirror": "^0.1.8",
"@textcomplete/core": "^0.1.8",
"@types/codemirror": "0.0.56",
"@types/node": "^14.14.19",
"@typescript-eslint/eslint-plugin": "4.11.1",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-module-resolver": "4.1.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"eslint": "^7.17.0",
"eslint-plugin-module-resolver": "^1.2.0",
"prettier": "2.x.x"
"@babel/preset-typescript": "7.x.x",
"@types/codemirror": "0.x.x",
"@types/node": "14.x.x",
"@typescript-eslint/eslint-plugin": "4.x.x",
"@typescript-eslint/parser": "4.x.x",
"babel-plugin-module-resolver": "^4.1.0",
"eslint": "7.x.x",
"eslint-plugin-module-resolver": "1.x.x",
"prettier": "2.x.x",
"typescript": "4.x.x"
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
//const cm = CodeMirror(document.getElementById('editor'))

//cm.on(document.body,"beforeChange", (e)=>{e.preventDefault(); e.stopPropagation(); CodeMirror.Pass});
const cmEditor = new CodeMirrorEditor(codeMirror);
const cmEditor = new CodeMirrorEditor(cm);
const textcomplete = new Textcomplete(cmEditor, [strategy], option);
},
};
50 changes: 19 additions & 31 deletions src/wiki_completions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*eslint no-debugger: false*/
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
Expand All @@ -20,10 +21,11 @@ const db = inkdrop && inkdrop?.main?.dataStore?.getLocalDB();
//@ts-ignore
const cursor = inkdrop && inkdrop?.codeMirror?.getCursor();
//experimental
const cmParentElement = document.querySelector("#app-container > div.main-layout.main-layout-slim > div.editor-layout > div.mde-layout > div > div.mde > div > div > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code")
const cmParentElement = document.querySelector(
"#app-container > div.main-layout.main-layout-slim > div.editor-layout > div.mde-layout > div > div.mde > div > div > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code"
);

export const gatherCandidates = async (term) => {
console.log(term);
const note = await db.utils.search(`title:${term}`);

if (note?.docs && note.docs.length > 0) {
Expand All @@ -39,29 +41,23 @@ export const strategy = {
// (Optional) This function is called on every change before matching. The
// first argument is the string from head to cursor. If it returns `false`,
// following matching phase isn't started.
context: (beforeCursor:string) => {
context: (beforeCursor: string) => {
// Return false if the cursor is in code block or inline code notation
// to stop executing the matching phase.
// console.log(beforeCursor.slice(-2));
// console.log(beforeCursor.slice(-2) === "[[");
// debugger;
/*
/*
if (beforeCursor.indexOf("[") > -1) {
const reversedCursor = beforeCursor.split("").reverse();
if (
reversedCursor.indexOf("[") < reversedCursor.indexOf("]") ||
reversedCursor.indexOf("]") < 0
) {
console.log("true");
return true;
}
}
*/
//console.log("false");

return true;
*/

return true;
},
// !isInClode(beforeCursor),
// (Required) On every change, the string from head to cursor tests with the
Expand All @@ -78,19 +74,11 @@ export const strategy = {
// function is called. The first argument is the captured substring.
// You can callback only once for each search.
search: async (
term :string,
callback:((results:SearchResult<string>[])=> void),
match : RegExpMatchArray
term: string,
callback: (results: SearchResult<string>[]) => void,
match: RegExpMatchArray
) => {
// debugger;
/*
console.log("term " + term);
const groups = match.groups;
const a = [];
let matched =groups?.findIndex(element => element === term);
var searchTerm =(matched && matched === (groups.length - 1))?
*/
callback(await gatherCandidates(term))
callback(await gatherCandidates(term));
},
// (Optional) Whether the search results are cached. Default false.
cache: false,
Expand All @@ -104,9 +92,9 @@ export const strategy = {
// Note that it can return a string or an array of two strings. If it returns
// an array, the matched substring will be replaced by the concatenated string
// and the cursor will be set between first and second strings.
replace: (result /*: ResultType): string*/) =>{
console.log(result)
return `[[${result}]]`} //["[[" + `${result}` + "]]",""],}
replace: (result /*: ResultType): string*/) => {
return `[[${result}]]`;
},
};
export const option = {
// Configure a dropdown UI.
Expand All @@ -118,16 +106,16 @@ export const option = {
// Placement of the dropdown. "auto", "top" or "bottom".
// placement: "auto",
// Return header and footer elements' content
// header: (results) => "",
// footer: (results) => "",
// header: (results) => "",
// footer: (results) => "",
// Whether activate the opposite side item on pressing up or
// down key when an edge item is active.
rotate: false,
parent: document.body,//.querySelector("#app-container > div.main-layout.main-layout-slim > div.editor-layout > div.mde-layout > div > div.mde > div > div > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code"),
parent: document.body, //.querySelector("#app-container > div.main-layout.main-layout-slim > div.editor-layout > div.mde-layout > div > div.mde > div > div > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code"),
// Configure CSS style of the dropdown element.
// style: { display: "none", position: "absolute", zIndex: "1000" },
// The parent node of the dropdown element.
// parent: document.body,
// parent: document.body,

item: {
// Class attribute of the each dropdown item element.
Expand Down
33 changes: 12 additions & 21 deletions styles/wiki_link.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,26 @@
text-decoration: underline;
}

body, html {
padding: 15px;
}

#editor {
border: 1px solid #DDD;
}


.textcomplete-dropdown {
border: 1px solid #ddd;
//so it's easier to see for now
background-color: black;
list-style: none;
padding: 0;
margin: 0;
border: 1px solid #ddd;
//so it's easier to see for now
background-color: rgba(0, 0, 0, 0.1);
list-style: none;
padding: 1px;
margin: 0;
}
.textcomplete-dropdown li {
margin: 0;
margin: 0;
}
.textcomplete-footer,
.textcomplete-item {
border-top: 1px solid #ddd;
border-top: 1px solid #ddd;
}
.textcomplete-item {
padding: 2px 5px;
cursor: pointer;
padding: 2px 5px;
cursor: pointer;
}
.textcomplete-item:hover,
.textcomplete-item.active {
background-color: rgb(110, 183, 219);
}
background-color: rgb(110, 183, 219);
}
5 changes: 5 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"noEmit": true
}
}
Loading

0 comments on commit db29472

Please sign in to comment.