Adds license headers, fixes indentation

This commit is contained in:
Simon Schödler 2023-04-04 10:50:20 +02:00
parent 63b8949f20
commit 8638b49812
17 changed files with 214 additions and 114 deletions

View file

@ -5,6 +5,6 @@ root = true
charset = utf-8 charset = utf-8
end_of_line = lf end_of_line = lf
insert_final_newline = true insert_final_newline = true
indent_style = tab indent_style = space
indent_size = 4 indent_size = 2
tab_width = 4 tab_width = 2

View file

@ -1,23 +1,23 @@
{ {
"root": true, "root": true,
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"env": { "node": true }, "env": { "node": true },
"plugins": [ "plugins": [
"@typescript-eslint" "@typescript-eslint"
], ],
"extends": [ "extends": [
"eslint:recommended", "eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended" "plugin:@typescript-eslint/recommended"
], ],
"parserOptions": { "parserOptions": {
"sourceType": "module" "sourceType": "module"
}, },
"rules": { "rules": {
"no-unused-vars": "off", "no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
"@typescript-eslint/ban-ts-comment": "off", "@typescript-eslint/ban-ts-comment": "off",
"no-prototype-builtins": "off", "no-prototype-builtins": "off",
"@typescript-eslint/no-empty-function": "off" "@typescript-eslint/no-empty-function": "off"
} }
} }

2
.gitignore vendored
View file

@ -19,4 +19,4 @@ main.js
data.json data.json
# Exclude macOS Finder (System Explorer) View States # Exclude macOS Finder (System Explorer) View States
.DS_Store .DS_Store

View file

@ -1,5 +1,5 @@
{ {
"singleQuote": true, "singleQuote": true,
"tabWidth": 2, "tabWidth": 2,
"useTabs": false "useTabs": false
} }

View file

@ -23,7 +23,6 @@ which will insert the following link:
![image](https://user-images.githubusercontent.com/38029550/229280048-fe7a8e31-8cbf-4090-a7f0-4bf0b83814d7.png) ![image](https://user-images.githubusercontent.com/38029550/229280048-fe7a8e31-8cbf-4090-a7f0-4bf0b83814d7.png)
## How to install manually ## How to install manually
1. Clone this repo. 1. Clone this repo.

View file

@ -12,31 +12,31 @@ if you want to view the source, please visit the github repository of this plugi
const prod = (process.argv[2] === 'production'); const prod = (process.argv[2] === 'production');
esbuild.build({ esbuild.build({
banner: { banner: {
js: banner, js: banner,
}, },
entryPoints: ['src/main.ts'], entryPoints: ['src/main.ts'],
bundle: true, bundle: true,
external: [ external: [
'obsidian', 'obsidian',
'electron', 'electron',
'@codemirror/autocomplete', '@codemirror/autocomplete',
'@codemirror/collab', '@codemirror/collab',
'@codemirror/commands', '@codemirror/commands',
'@codemirror/language', '@codemirror/language',
'@codemirror/lint', '@codemirror/lint',
'@codemirror/search', '@codemirror/search',
'@codemirror/state', '@codemirror/state',
'@codemirror/view', '@codemirror/view',
'@lezer/common', '@lezer/common',
'@lezer/highlight', '@lezer/highlight',
'@lezer/lr', '@lezer/lr',
...builtins], ...builtins],
format: 'cjs', format: 'cjs',
watch: !prod, watch: !prod,
target: 'es2018', target: 'es2018',
logLevel: "info", logLevel: "info",
sourcemap: prod ? false : 'inline', sourcemap: prod ? false : 'inline',
treeShaking: true, treeShaking: true,
outfile: './main.js', outfile: './main.js',
}).catch(() => process.exit(1)); }).catch(() => process.exit(1));

View file

@ -1,10 +1,10 @@
{ {
"id": "crossbow", "id": "crossbow",
"name": "Crossbow", "name": "Crossbow",
"version": "1.0.0", "version": "1.0.0",
"minAppVersion": "0.15.0", "minAppVersion": "0.15.0",
"description": "Obsidian plugin to find possible backlinks in your notes.", "description": "Plugin to find possible backlinks in your notes.",
"author": "Obsidian", "author": "shoedler",
"authorUrl": "https://github.com/shoedler", "authorUrl": "https://github.com/shoedler",
"isDesktopOnly": false "isDesktopOnly": false
} }

View file

@ -1,24 +1,24 @@
{ {
"name": "crossbow", "name": "crossbow",
"version": "1.0.0", "version": "1.0.0",
"description": "Obsidian plugin to find possible backlinks in your notes (https://obsidian.md)", "description": "Obsidian plugin to find possible backlinks in your notes (https://obsidian.md)",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"dev": "node esbuild.config.mjs", "dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json" "version": "node version-bump.mjs && git add manifest.json versions.json"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "shoedler",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^16.11.6", "@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0", "@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0", "@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0", "builtin-modules": "3.3.0",
"esbuild": "0.14.47", "esbuild": "0.14.47",
"obsidian": "latest", "obsidian": "latest",
"tslib": "2.4.0", "tslib": "2.4.0",
"typescript": "4.7.4" "typescript": "4.7.4"
} }
} }

View file

@ -1,3 +1,15 @@
// Copyright (C) 2023 - shoedler - github.com/shoedler
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
import { Editor, EditorPosition } from 'obsidian'; import { Editor, EditorPosition } from 'obsidian';
import { stripMarkdown } from './util'; import { stripMarkdown } from './util';

View file

@ -1,3 +1,15 @@
// Copyright (C) 2023 - shoedler - github.com/shoedler
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
import { addIcon } from 'obsidian'; import { addIcon } from 'obsidian';
const crossbowIcon = { const crossbowIcon = {

View file

@ -1,3 +1,15 @@
// Copyright (C) 2023 - shoedler - github.com/shoedler
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
import { CrossbowView } from './view/view'; import { CrossbowView } from './view/view';
import { registerCrossbowIcons } from './icons'; import { registerCrossbowIcons } from './icons';
import { import {
@ -6,7 +18,6 @@ import {
MarkdownView, MarkdownView,
Plugin, Plugin,
TFile, TFile,
EditorPosition,
CachedMetadata, CachedMetadata,
} from 'obsidian'; } from 'obsidian';
import { CrossbowSettingTab } from './settings'; import { CrossbowSettingTab } from './settings';

View file

@ -1,3 +1,15 @@
// Copyright (C) 2023 - shoedler - github.com/shoedler
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
import { App, PluginSettingTab, Setting } from 'obsidian'; import { App, PluginSettingTab, Setting } from 'obsidian';
import CrossbowPlugin, { CrossbowPluginSettings } from './main'; import CrossbowPlugin, { CrossbowPluginSettings } from './main';

View file

@ -1,3 +1,15 @@
// Copyright (C) 2023 - shoedler - github.com/shoedler
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
import { EditorPosition } from 'obsidian'; import { EditorPosition } from 'obsidian';
import { CacheMatch } from './main'; import { CacheMatch } from './main';
import { TreeItem, TreeItemBase } from './view/treeItem'; import { TreeItem, TreeItemBase } from './view/treeItem';
@ -17,8 +29,9 @@ export class Suggestion extends TreeItem<string> {
return this.value; return this.value;
} }
public getChildren = () => public getChildren() {
Array.from(this.childrenWrapper.children) as Occurrence[]; return Array.from(this.childrenWrapper.children) as Occurrence[];
}
public sortChildren(): void { public sortChildren(): void {
this.getChildren() this.getChildren()
@ -45,8 +58,9 @@ export class Occurrence extends TreeItem<EditorPosition> {
return `On line ${this.value.line}:${this.value.ch}`; return `On line ${this.value.line}:${this.value.ch}`;
} }
public getChildren = () => public getChildren() {
Array.from(this.childrenWrapper.children) as Match[]; return Array.from(this.childrenWrapper.children) as Match[];
}
public sortChildren(): void { public sortChildren(): void {
this.getChildren().sort( this.getChildren().sort(

View file

@ -1,3 +1,15 @@
// Copyright (C) 2023 - shoedler - github.com/shoedler
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Credit: https://github.com/stiang/remove-markdown // Credit: https://github.com/stiang/remove-markdown
export interface StripMarkdownOptions { export interface StripMarkdownOptions {

View file

@ -1,3 +1,15 @@
// Copyright (C) 2023 - shoedler - github.com/shoedler
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
import { ButtonComponent, getIcon } from 'obsidian'; import { ButtonComponent, getIcon } from 'obsidian';
export abstract class TreeItemBase<TData> extends HTMLElement { export abstract class TreeItemBase<TData> extends HTMLElement {
@ -37,15 +49,17 @@ export abstract class TreeItemBase<TData> extends HTMLElement {
} }
public connectedCallback() { public connectedCallback() {
console.log(this.text, this.parentElement, this.parentNode);
this.inner.setText(this.text); this.inner.setText(this.text);
} }
public abstract sortChildren(): void; public abstract sortChildren(): void;
public setDisable = () => { public setDisable() {
this.mainWrapper.style.textDecoration = 'line-through'; this.mainWrapper.style.textDecoration = 'line-through';
this.buttons.forEach((button) => button.setDisabled(true)); this.buttons.forEach((button) => button.setDisabled(true));
}; }
public addOnClick = ( public addOnClick = (
listener: (this: HTMLDivElement, ev: HTMLElementEventMap['click']) => any listener: (this: HTMLDivElement, ev: HTMLElementEventMap['click']) => any
@ -87,10 +101,10 @@ export abstract class TreeItem<TData> extends TreeItemBase<TData> {
this.addClass('is-collapsed'); this.addClass('is-collapsed');
this.mainWrapper.addClass('mod-collapsible'); this.mainWrapper.addClass('mod-collapsible');
this.childrenWrapper = createEl('div', { cls: 'tree-item-children' }); this.childrenWrapper = this.createDiv({ cls: 'tree-item-children' });
this.childrenWrapper.style.display = 'none'; this.childrenWrapper.style.display = 'none';
this.iconWrapper = createEl('div', { this.iconWrapper = this.createDiv({
cls: ['tree-item-icon', 'collapse-icon'], cls: ['tree-item-icon', 'collapse-icon'],
}); });
this.iconWrapper.appendChild(getIcon('right-triangle')!); this.iconWrapper.appendChild(getIcon('right-triangle')!);
@ -106,31 +120,29 @@ export abstract class TreeItem<TData> extends TreeItemBase<TData> {
public abstract getChildren(): TreeItemBase<any>[]; public abstract getChildren(): TreeItemBase<any>[];
public isCollapsed = () => this.hasClass('is-collapsed'); public isCollapsed() {
return this.hasClass('is-collapsed');
}
public expand = () => { public expand() {
this.removeClass('is-collapsed'); this.removeClass('is-collapsed');
this.childrenWrapper.style.display = 'block'; this.childrenWrapper.style.display = 'block';
}; }
public collapse = () => { public collapse() {
this.addClass('is-collapsed'); this.addClass('is-collapsed');
this.childrenWrapper.style.display = 'none'; this.childrenWrapper.style.display = 'none';
}; }
public setDisable = () => { public setDisable() {
super.setDisable(); super.setDisable();
this.mainWrapper.style.textDecoration = 'line-through'; this.mainWrapper.style.textDecoration = 'line-through';
Array.from(this.childrenWrapper.children).forEach((child) => Array.from(this.childrenWrapper.children).forEach((child) =>
(child as TreeItemBase<any>).setDisable() (child as TreeItemBase<any>).setDisable()
); );
}; }
public addChildren = (children: TreeItemBase<any>[]) => { public addChildren(children: TreeItemBase<any>[]) {
console.log('addChildren', this.childrenWrapper, children); this.childrenWrapper.replaceChildren(...children);
}
children.forEach((child) => {
this.childrenWrapper.appendChild(child);
});
};
} }

View file

@ -1,3 +1,15 @@
// Copyright (C) 2023 - shoedler - github.com/shoedler
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
import { EditorPosition, ItemView, WorkspaceLeaf } from 'obsidian'; import { EditorPosition, ItemView, WorkspaceLeaf } from 'obsidian';
import { Match, Occurrence, Suggestion } from 'src/suggestion'; import { Match, Occurrence, Suggestion } from 'src/suggestion';
import CrossbowPlugin, { CacheMatch } from 'src/main'; import CrossbowPlugin, { CacheMatch } from 'src/main';
@ -185,6 +197,10 @@ export class CrossbowView extends ItemView {
suggestion.addChildren(occurrences); suggestion.addChildren(occurrences);
const w = window as any;
w.suggestions = w.suggestions || [];
w.suggestions.push({ suggestion, occurrences });
return suggestion; return suggestion;
}; };
} }

View file

@ -1,3 +1,3 @@
{ {
"1.0.0": "0.15.0" "1.0.0": "0.15.0"
} }