From 8638b49812289ec531c2e66cea8327ffe4c84049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sch=C3=B6dler?= Date: Tue, 4 Apr 2023 10:50:20 +0200 Subject: [PATCH] Adds license headers, fixes indentation --- .editorconfig | 6 ++--- .eslintrc | 44 +++++++++++++++++----------------- .gitignore | 2 +- .prettierrc | 6 ++--- README.md | 1 - esbuild.config.mjs | 54 +++++++++++++++++++++--------------------- manifest.json | 18 +++++++------- package.json | 46 +++++++++++++++++------------------ src/editorExtension.ts | 12 ++++++++++ src/icons.ts | 12 ++++++++++ src/main.ts | 13 +++++++++- src/settings.ts | 12 ++++++++++ src/suggestion.ts | 22 +++++++++++++---- src/util.ts | 12 ++++++++++ src/view/treeItem.ts | 48 +++++++++++++++++++++++-------------- src/view/view.ts | 16 +++++++++++++ versions.json | 4 ++-- 17 files changed, 214 insertions(+), 114 deletions(-) diff --git a/.editorconfig b/.editorconfig index 84b8a66..72201e7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,6 +5,6 @@ root = true charset = utf-8 end_of_line = lf insert_final_newline = true -indent_style = tab -indent_size = 4 -tab_width = 4 +indent_style = space +indent_size = 2 +tab_width = 2 diff --git a/.eslintrc b/.eslintrc index 0807290..d8158db 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,23 +1,23 @@ { - "root": true, - "parser": "@typescript-eslint/parser", - "env": { "node": true }, - "plugins": [ - "@typescript-eslint" - ], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended" - ], - "parserOptions": { - "sourceType": "module" - }, - "rules": { - "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], - "@typescript-eslint/ban-ts-comment": "off", - "no-prototype-builtins": "off", - "@typescript-eslint/no-empty-function": "off" - } - } \ No newline at end of file + "root": true, + "parser": "@typescript-eslint/parser", + "env": { "node": true }, + "plugins": [ + "@typescript-eslint" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended" + ], + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], + "@typescript-eslint/ban-ts-comment": "off", + "no-prototype-builtins": "off", + "@typescript-eslint/no-empty-function": "off" + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index e09a007..61ccc0f 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,4 @@ main.js data.json # Exclude macOS Finder (System Explorer) View States -.DS_Store +.DS_Store \ No newline at end of file diff --git a/.prettierrc b/.prettierrc index 0092d69..150714b 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,5 @@ { - "singleQuote": true, - "tabWidth": 2, - "useTabs": false + "singleQuote": true, + "tabWidth": 2, + "useTabs": false } \ No newline at end of file diff --git a/README.md b/README.md index 0326033..0f34bdc 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ which will insert the following link: ![image](https://user-images.githubusercontent.com/38029550/229280048-fe7a8e31-8cbf-4090-a7f0-4bf0b83814d7.png) - ## How to install manually 1. Clone this repo. diff --git a/esbuild.config.mjs b/esbuild.config.mjs index ec61db6..b05001c 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -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'); esbuild.build({ - banner: { - js: banner, - }, - entryPoints: ['src/main.ts'], - bundle: true, - external: [ - 'obsidian', - 'electron', - '@codemirror/autocomplete', - '@codemirror/collab', - '@codemirror/commands', - '@codemirror/language', - '@codemirror/lint', - '@codemirror/search', - '@codemirror/state', - '@codemirror/view', - '@lezer/common', - '@lezer/highlight', - '@lezer/lr', - ...builtins], - format: 'cjs', - watch: !prod, - target: 'es2018', - logLevel: "info", - sourcemap: prod ? false : 'inline', - treeShaking: true, - outfile: './main.js', + banner: { + js: banner, + }, + entryPoints: ['src/main.ts'], + bundle: true, + external: [ + 'obsidian', + 'electron', + '@codemirror/autocomplete', + '@codemirror/collab', + '@codemirror/commands', + '@codemirror/language', + '@codemirror/lint', + '@codemirror/search', + '@codemirror/state', + '@codemirror/view', + '@lezer/common', + '@lezer/highlight', + '@lezer/lr', + ...builtins], + format: 'cjs', + watch: !prod, + target: 'es2018', + logLevel: "info", + sourcemap: prod ? false : 'inline', + treeShaking: true, + outfile: './main.js', }).catch(() => process.exit(1)); diff --git a/manifest.json b/manifest.json index 9548dc4..2ad036b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ { - "id": "crossbow", - "name": "Crossbow", - "version": "1.0.0", - "minAppVersion": "0.15.0", - "description": "Obsidian plugin to find possible backlinks in your notes.", - "author": "Obsidian", - "authorUrl": "https://github.com/shoedler", - "isDesktopOnly": false -} + "id": "crossbow", + "name": "Crossbow", + "version": "1.0.0", + "minAppVersion": "0.15.0", + "description": "Plugin to find possible backlinks in your notes.", + "author": "shoedler", + "authorUrl": "https://github.com/shoedler", + "isDesktopOnly": false +} \ No newline at end of file diff --git a/package.json b/package.json index 7a6c566..417f52e 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,24 @@ { - "name": "crossbow", - "version": "1.0.0", - "description": "Obsidian plugin to find possible backlinks in your notes (https://obsidian.md)", - "main": "main.js", - "scripts": { - "dev": "node esbuild.config.mjs", - "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", - "version": "node version-bump.mjs && git add manifest.json versions.json" - }, - "keywords": [], - "author": "", - "license": "MIT", - "devDependencies": { - "@types/node": "^16.11.6", - "@typescript-eslint/eslint-plugin": "5.29.0", - "@typescript-eslint/parser": "5.29.0", - "builtin-modules": "3.3.0", - "esbuild": "0.14.47", - "obsidian": "latest", - "tslib": "2.4.0", - "typescript": "4.7.4" - } -} + "name": "crossbow", + "version": "1.0.0", + "description": "Obsidian plugin to find possible backlinks in your notes (https://obsidian.md)", + "main": "main.js", + "scripts": { + "dev": "node esbuild.config.mjs", + "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", + "version": "node version-bump.mjs && git add manifest.json versions.json" + }, + "keywords": [], + "author": "shoedler", + "license": "MIT", + "devDependencies": { + "@types/node": "^16.11.6", + "@typescript-eslint/eslint-plugin": "5.29.0", + "@typescript-eslint/parser": "5.29.0", + "builtin-modules": "3.3.0", + "esbuild": "0.14.47", + "obsidian": "latest", + "tslib": "2.4.0", + "typescript": "4.7.4" + } +} \ No newline at end of file diff --git a/src/editorExtension.ts b/src/editorExtension.ts index da8f785..7a3b436 100644 --- a/src/editorExtension.ts +++ b/src/editorExtension.ts @@ -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 { stripMarkdown } from './util'; diff --git a/src/icons.ts b/src/icons.ts index aefe09b..f534e13 100644 --- a/src/icons.ts +++ b/src/icons.ts @@ -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'; const crossbowIcon = { diff --git a/src/main.ts b/src/main.ts index 85feb6b..5cc2f6a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 { registerCrossbowIcons } from './icons'; import { @@ -6,7 +18,6 @@ import { MarkdownView, Plugin, TFile, - EditorPosition, CachedMetadata, } from 'obsidian'; import { CrossbowSettingTab } from './settings'; diff --git a/src/settings.ts b/src/settings.ts index dd1047c..a39ea7f 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -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 CrossbowPlugin, { CrossbowPluginSettings } from './main'; diff --git a/src/suggestion.ts b/src/suggestion.ts index fa2c518..b720c8d 100644 --- a/src/suggestion.ts +++ b/src/suggestion.ts @@ -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 { CacheMatch } from './main'; import { TreeItem, TreeItemBase } from './view/treeItem'; @@ -17,8 +29,9 @@ export class Suggestion extends TreeItem { return this.value; } - public getChildren = () => - Array.from(this.childrenWrapper.children) as Occurrence[]; + public getChildren() { + return Array.from(this.childrenWrapper.children) as Occurrence[]; + } public sortChildren(): void { this.getChildren() @@ -45,8 +58,9 @@ export class Occurrence extends TreeItem { return `On line ${this.value.line}:${this.value.ch}`; } - public getChildren = () => - Array.from(this.childrenWrapper.children) as Match[]; + public getChildren() { + return Array.from(this.childrenWrapper.children) as Match[]; + } public sortChildren(): void { this.getChildren().sort( diff --git a/src/util.ts b/src/util.ts index 7077152..3e5c284 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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 export interface StripMarkdownOptions { diff --git a/src/view/treeItem.ts b/src/view/treeItem.ts index 076334f..56f3220 100644 --- a/src/view/treeItem.ts +++ b/src/view/treeItem.ts @@ -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'; export abstract class TreeItemBase extends HTMLElement { @@ -37,15 +49,17 @@ export abstract class TreeItemBase extends HTMLElement { } public connectedCallback() { + console.log(this.text, this.parentElement, this.parentNode); + this.inner.setText(this.text); } public abstract sortChildren(): void; - public setDisable = () => { + public setDisable() { this.mainWrapper.style.textDecoration = 'line-through'; this.buttons.forEach((button) => button.setDisabled(true)); - }; + } public addOnClick = ( listener: (this: HTMLDivElement, ev: HTMLElementEventMap['click']) => any @@ -87,10 +101,10 @@ export abstract class TreeItem extends TreeItemBase { this.addClass('is-collapsed'); 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.iconWrapper = createEl('div', { + this.iconWrapper = this.createDiv({ cls: ['tree-item-icon', 'collapse-icon'], }); this.iconWrapper.appendChild(getIcon('right-triangle')!); @@ -106,31 +120,29 @@ export abstract class TreeItem extends TreeItemBase { public abstract getChildren(): TreeItemBase[]; - public isCollapsed = () => this.hasClass('is-collapsed'); + public isCollapsed() { + return this.hasClass('is-collapsed'); + } - public expand = () => { + public expand() { this.removeClass('is-collapsed'); this.childrenWrapper.style.display = 'block'; - }; + } - public collapse = () => { + public collapse() { this.addClass('is-collapsed'); this.childrenWrapper.style.display = 'none'; - }; + } - public setDisable = () => { + public setDisable() { super.setDisable(); this.mainWrapper.style.textDecoration = 'line-through'; Array.from(this.childrenWrapper.children).forEach((child) => (child as TreeItemBase).setDisable() ); - }; + } - public addChildren = (children: TreeItemBase[]) => { - console.log('addChildren', this.childrenWrapper, children); - - children.forEach((child) => { - this.childrenWrapper.appendChild(child); - }); - }; + public addChildren(children: TreeItemBase[]) { + this.childrenWrapper.replaceChildren(...children); + } } diff --git a/src/view/view.ts b/src/view/view.ts index cd451d4..a7c3d48 100644 --- a/src/view/view.ts +++ b/src/view/view.ts @@ -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 { Match, Occurrence, Suggestion } from 'src/suggestion'; import CrossbowPlugin, { CacheMatch } from 'src/main'; @@ -185,6 +197,10 @@ export class CrossbowView extends ItemView { suggestion.addChildren(occurrences); + const w = window as any; + w.suggestions = w.suggestions || []; + w.suggestions.push({ suggestion, occurrences }); + return suggestion; }; } diff --git a/versions.json b/versions.json index 26382a1..f671e66 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "1.0.0": "0.15.0" -} + "1.0.0": "0.15.0" +} \ No newline at end of file