Compare commits

..

No commits in common. "master" and "agents-md" have entirely different histories.

13 changed files with 132 additions and 5341 deletions

3
.eslintignore Normal file
View file

@ -0,0 +1,3 @@
node_modules/
main.js

23
.eslintrc Normal file
View file

@ -0,0 +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"
}
}

View file

@ -1,28 +0,0 @@
name: Node.js build
on:
push:
branches: ["**"]
pull_request:
branches: ["**"]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- run: npm run lint

View file

@ -7,7 +7,7 @@ The repo depends on the latest plugin API (obsidian.d.ts) in TypeScript Definiti
This sample plugin demonstrates some of the basic functionality the plugin API can do. This sample plugin demonstrates some of the basic functionality the plugin API can do.
- Adds a ribbon icon, which shows a Notice when clicked. - Adds a ribbon icon, which shows a Notice when clicked.
- Adds a command "Open modal (simple)" which opens a Modal. - Adds a command "Open Sample Modal" which opens a Modal.
- Adds a plugin setting tab to the settings page. - Adds a plugin setting tab to the settings page.
- Registers a global click event and output 'click' to the console. - Registers a global click event and output 'click' to the console.
- Registers a global interval which logs 'setInterval' to the console. - Registers a global interval which logs 'setInterval' to the console.
@ -55,11 +55,15 @@ Quick starting guide for new plugin devs:
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`. - Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
## Improve code quality with eslint ## Improve code quality with eslint (optional)
- [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code. - [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code.
- This project already has eslint preconfigured, you can invoke a check by running`npm run lint` - To use eslint with this project, make sure to install eslint from terminal:
- Together with a custom eslint [plugin](https://github.com/obsidianmd/eslint-plugin) for Obsidan specific code guidelines. - `npm install -g eslint`
- A GitHub action is preconfigured to automatically lint every commit on all branches. - To use eslint to analyze this project use this command:
- `eslint main.ts`
- eslint will then create a report with suggestions for code improvement by file and line number.
- If your source code is in a folder, such as `src`, you can use eslint with this command to analyze all files in that folder:
- `eslint ./src/`
## Funding URL ## Funding URL
@ -87,4 +91,4 @@ If you have multiple URLs, you can also do:
## API Documentation ## API Documentation
See https://docs.obsidian.md See https://github.com/obsidianmd/obsidian-api

View file

@ -1,6 +1,6 @@
import esbuild from "esbuild"; import esbuild from "esbuild";
import process from "process"; import process from "process";
import { builtinModules } from 'node:module'; import builtins from "builtin-modules";
const banner = const banner =
`/* `/*
@ -15,7 +15,7 @@ const context = await esbuild.context({
banner: { banner: {
js: banner, js: banner,
}, },
entryPoints: ["src/main.ts"], entryPoints: ["main.ts"],
bundle: true, bundle: true,
external: [ external: [
"obsidian", "obsidian",
@ -31,7 +31,7 @@ const context = await esbuild.context({
"@lezer/common", "@lezer/common",
"@lezer/highlight", "@lezer/highlight",
"@lezer/lr", "@lezer/lr",
...builtinModules], ...builtins],
format: "cjs", format: "cjs",
target: "es2018", target: "es2018",
logLevel: "info", logLevel: "info",

View file

@ -1,34 +0,0 @@
import tseslint from 'typescript-eslint';
import obsidianmd from "eslint-plugin-obsidianmd";
import globals from "globals";
import { globalIgnores } from "eslint/config";
export default tseslint.config(
{
languageOptions: {
globals: {
...globals.browser,
},
parserOptions: {
projectService: {
allowDefaultProject: [
'eslint.config.js',
'manifest.json'
]
},
tsconfigRootDir: import.meta.dirname,
extraFileExtensions: ['.json']
},
},
},
...obsidianmd.configs.recommended,
globalIgnores([
"node_modules",
"dist",
"esbuild.config.mjs",
"eslint.config.js",
"version-bump.mjs",
"versions.json",
"main.js",
]),
);

View file

@ -1,8 +1,15 @@
import {App, Editor, MarkdownView, Modal, Notice, Plugin} from 'obsidian'; import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import {DEFAULT_SETTINGS, MyPluginSettings, SampleSettingTab} from "./settings";
// Remember to rename these classes and interfaces! // Remember to rename these classes and interfaces!
interface MyPluginSettings {
mySetting: string;
}
const DEFAULT_SETTINGS: MyPluginSettings = {
mySetting: 'default'
}
export default class MyPlugin extends Plugin { export default class MyPlugin extends Plugin {
settings: MyPluginSettings; settings: MyPluginSettings;
@ -10,35 +17,38 @@ export default class MyPlugin extends Plugin {
await this.loadSettings(); await this.loadSettings();
// This creates an icon in the left ribbon. // This creates an icon in the left ribbon.
this.addRibbonIcon('dice', 'Sample', (evt: MouseEvent) => { const ribbonIconEl = this.addRibbonIcon('dice', 'Sample Plugin', (evt: MouseEvent) => {
// Called when the user clicks the icon. // Called when the user clicks the icon.
new Notice('This is a notice!'); new Notice('This is a notice!');
}); });
// Perform additional things with the ribbon
ribbonIconEl.addClass('my-plugin-ribbon-class');
// This adds a status bar item to the bottom of the app. Does not work on mobile apps. // This adds a status bar item to the bottom of the app. Does not work on mobile apps.
const statusBarItemEl = this.addStatusBarItem(); const statusBarItemEl = this.addStatusBarItem();
statusBarItemEl.setText('Status bar text'); statusBarItemEl.setText('Status Bar Text');
// This adds a simple command that can be triggered anywhere // This adds a simple command that can be triggered anywhere
this.addCommand({ this.addCommand({
id: 'open-modal-simple', id: 'open-sample-modal-simple',
name: 'Open modal (simple)', name: 'Open sample modal (simple)',
callback: () => { callback: () => {
new SampleModal(this.app).open(); new SampleModal(this.app).open();
} }
}); });
// This adds an editor command that can perform some operation on the current editor instance // This adds an editor command that can perform some operation on the current editor instance
this.addCommand({ this.addCommand({
id: 'replace-selected', id: 'sample-editor-command',
name: 'Replace selected content', name: 'Sample editor command',
editorCallback: (editor: Editor, view: MarkdownView) => { editorCallback: (editor: Editor, view: MarkdownView) => {
editor.replaceSelection('Sample editor command'); console.log(editor.getSelection());
editor.replaceSelection('Sample Editor Command');
} }
}); });
// This adds a complex command that can check whether the current state of the app allows execution of the command // This adds a complex command that can check whether the current state of the app allows execution of the command
this.addCommand({ this.addCommand({
id: 'open-modal-complex', id: 'open-sample-modal-complex',
name: 'Open modal (complex)', name: 'Open sample modal (complex)',
checkCallback: (checking: boolean) => { checkCallback: (checking: boolean) => {
// Conditions to check // Conditions to check
const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView); const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
@ -52,7 +62,6 @@ export default class MyPlugin extends Plugin {
// This command will only show up in Command Palette when the check function returns true // This command will only show up in Command Palette when the check function returns true
return true; return true;
} }
return false;
} }
}); });
@ -62,19 +71,19 @@ export default class MyPlugin extends Plugin {
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin) // If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
// Using this function will automatically remove the event listener when this plugin is disabled. // Using this function will automatically remove the event listener when this plugin is disabled.
this.registerDomEvent(document, 'click', (evt: MouseEvent) => { this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
new Notice("Click"); console.log('click', evt);
}); });
// When registering intervals, this function will automatically clear the interval when the plugin is disabled. // When registering intervals, this function will automatically clear the interval when the plugin is disabled.
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000)); this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
} }
onunload() { onunload() {
} }
async loadSettings() { async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData() as Partial<MyPluginSettings>); this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
} }
async saveSettings() { async saveSettings() {
@ -88,7 +97,7 @@ class SampleModal extends Modal {
} }
onOpen() { onOpen() {
let {contentEl} = this; const {contentEl} = this;
contentEl.setText('Woah!'); contentEl.setText('Woah!');
} }
@ -97,3 +106,29 @@ class SampleModal extends Modal {
contentEl.empty(); contentEl.empty();
} }
} }
class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin;
constructor(app: App, plugin: MyPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const {containerEl} = this;
containerEl.empty();
new Setting(containerEl)
.setName('Setting #1')
.setDesc('It\'s a secret')
.addText(text => text
.setPlaceholder('Enter your secret')
.setValue(this.plugin.settings.mySetting)
.onChange(async (value) => {
this.plugin.settings.mySetting = value;
await this.plugin.saveSettings();
}));
}
}

View file

@ -1,11 +1,11 @@
{ {
"id": "bible-verse-parser", "id": "sample-plugin",
"name": "Bible Verse Parser", "name": "Sample Plugin",
"version": "0.1.0", "version": "1.0.0",
"minAppVersion": "0.15.0", "minAppVersion": "0.15.0",
"description": "Pastes the bible verses to the particular regex format.", "description": "Demonstrates some of the capabilities of the Obsidian API.",
"author": "abelmalzew", "author": "Obsidian",
"authorUrl": "https://github.com/f0tt3r", "authorUrl": "https://obsidian.md",
"fundingUrl": "https://github.com/f0tt3r", "fundingUrl": "https://obsidian.md/pricing",
"isDesktopOnly": false "isDesktopOnly": false
} }

5162
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,27 +3,22 @@
"version": "1.0.0", "version": "1.0.0",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)", "description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js", "main": "main.js",
"type": "module",
"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"
"lint": "eslint ."
}, },
"keywords": [], "keywords": [],
"license": "0-BSD", "author": "",
"license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "^16.11.6", "@types/node": "^16.11.6",
"esbuild": "0.25.5", "@typescript-eslint/eslint-plugin": "5.29.0",
"eslint-plugin-obsidianmd": "0.1.9", "@typescript-eslint/parser": "5.29.0",
"globals": "14.0.0", "builtin-modules": "3.3.0",
"esbuild": "0.17.3",
"obsidian": "latest",
"tslib": "2.4.0", "tslib": "2.4.0",
"typescript": "^5.8.3", "typescript": "4.7.4"
"typescript-eslint": "8.35.1",
"@eslint/js": "9.30.1",
"jiti": "2.6.1"
},
"dependencies": {
"obsidian": "latest"
} }
} }

View file

@ -1,36 +0,0 @@
import {App, PluginSettingTab, Setting} from "obsidian";
import MyPlugin from "./main";
export interface MyPluginSettings {
mySetting: string;
}
export const DEFAULT_SETTINGS: MyPluginSettings = {
mySetting: 'default'
}
export class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin;
constructor(app: App, plugin: MyPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const {containerEl} = this;
containerEl.empty();
new Setting(containerEl)
.setName('Settings #1')
.setDesc('It\'s a secret')
.addText(text => text
.setPlaceholder('Enter your secret')
.setValue(this.plugin.settings.mySetting)
.onChange(async (value) => {
this.plugin.settings.mySetting = value;
await this.plugin.saveSettings();
}));
}
}

View file

@ -1,22 +1,16 @@
{ {
"compilerOptions": { "compilerOptions": {
"baseUrl": "src", "baseUrl": ".",
"inlineSourceMap": true, "inlineSourceMap": true,
"inlineSources": true, "inlineSources": true,
"module": "ESNext", "module": "ESNext",
"target": "ES6", "target": "ES6",
"allowJs": true, "allowJs": true,
"noImplicitAny": true, "noImplicitAny": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"moduleResolution": "node", "moduleResolution": "node",
"importHelpers": true, "importHelpers": true,
"noUncheckedIndexedAccess": true,
"isolatedModules": true, "isolatedModules": true,
"strictNullChecks": true, "strictNullChecks": true,
"strictBindCallApply": true,
"allowSyntheticDefaultImports": true,
"useUnknownInCatchVariables": true,
"lib": [ "lib": [
"DOM", "DOM",
"ES5", "ES5",
@ -25,6 +19,6 @@
] ]
}, },
"include": [ "include": [
"src/**/*.ts" "**/*.ts"
] ]
} }

View file

@ -3,15 +3,12 @@ import { readFileSync, writeFileSync } from "fs";
const targetVersion = process.env.npm_package_version; const targetVersion = process.env.npm_package_version;
// read minAppVersion from manifest.json and bump version to target version // read minAppVersion from manifest.json and bump version to target version
const manifest = JSON.parse(readFileSync("manifest.json", "utf8")); let manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
const { minAppVersion } = manifest; const { minAppVersion } = manifest;
manifest.version = targetVersion; manifest.version = targetVersion;
writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t")); writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));
// update versions.json with target version and minAppVersion from manifest.json // update versions.json with target version and minAppVersion from manifest.json
// but only if the target version is not already in versions.json let versions = JSON.parse(readFileSync("versions.json", "utf8"));
const versions = JSON.parse(readFileSync('versions.json', 'utf8'));
if (!Object.values(versions).includes(minAppVersion)) {
versions[targetVersion] = minAppVersion; versions[targetVersion] = minAppVersion;
writeFileSync('versions.json', JSON.stringify(versions, null, '\t')); writeFileSync("versions.json", JSON.stringify(versions, null, "\t"));
}