mirror of
https://github.com/mildeveloper/obsidian-date-range-expander.git
synced 2026-07-22 12:20:32 +00:00
Compare commits
No commits in common. "main" and "0.9.1" have entirely different histories.
9 changed files with 856 additions and 73 deletions
144
.gitignore
vendored
144
.gitignore
vendored
|
|
@ -1,14 +1,136 @@
|
|||
# vscode
|
||||
.vscode
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# npm
|
||||
node_modules
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Don't include the compiled main.js file in the repo.
|
||||
# They should be uploaded to GitHub releases instead.
|
||||
main.js
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# obsidian
|
||||
data.json
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# vitepress build output
|
||||
**/.vitepress/dist
|
||||
|
||||
# vitepress cache directory
|
||||
**/.vitepress/cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
|
|
|||
21
README.md
21
README.md
|
|
@ -33,25 +33,8 @@ The plugin will then insert your date range using your configured format setting
|
|||
|
||||
- **Friendly date format**: Format for displaying dates in a more readable way in certains locations like the callout and alert boxes.
|
||||
- Default: DDD D MMM YYYY
|
||||
- Supports:
|
||||
- D: Single digit day (1-31)
|
||||
- DD: Two digit day with leading zero (01-31)
|
||||
- DDD: Three letter day abbreviation (Mon, Tue, etc.)
|
||||
- DDDD: Full day name (Monday, Tuesday, etc.)
|
||||
- M: Single digit month (1-12)
|
||||
- MM: Two digit month with leading zero (01-12)
|
||||
- MMM: Three letter month abbreviation (Jan, Feb, etc.)
|
||||
- MMMM: Full month name (January, February, etc.)
|
||||
- Y: Single digit year (0-9)
|
||||
- YY: Two digit year (00-99)
|
||||
- YYY: Three digit year (000-999)
|
||||
- YYYY: Full four digit year (0000-9999)
|
||||
- Examples:
|
||||
- DDD D MMM YYYY -> Fri 8 Mar 2024
|
||||
- MMMM D, YYYY -> March 8, 2024
|
||||
- DD/MM/YY -> 08/03/24
|
||||
- DDDD, MMMM D, YYYY -> Friday, March 8, 2024
|
||||
- YYYY-MM-DD -> 2024-03-08
|
||||
- Supports: D, DD, DDD, DDDD, M, MM, MMM, MMMM, Y, YY, YYY, YYYY
|
||||
- Example: Fri 15 Mar 2024
|
||||
|
||||
- **Date separator**: Character(s) used to separate dates in the sequence
|
||||
- Default: ", "
|
||||
|
|
|
|||
642
main.js
Normal file
642
main.js
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "date-range-expander",
|
||||
"name": "Date Range Expander",
|
||||
"version": "1.0.2",
|
||||
"version": "0.9.1",
|
||||
"minAppVersion": "1.5.8",
|
||||
"description": "Quickly add a range of day references given a date duration.",
|
||||
"author": "Mil",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "obsidian-date-range-expander",
|
||||
"version": "1.0.2",
|
||||
"version": "0.9.1",
|
||||
"description": "Quickly add a range of day references given a date duration.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ export class DateInputModal extends Modal {
|
|||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
|
||||
this.addStyles();
|
||||
this.setupKeyboardListener();
|
||||
this.createStartDateInput();
|
||||
this.createRangeOptions();
|
||||
|
|
@ -92,6 +93,32 @@ export class DateInputModal extends Modal {
|
|||
return dateCount;
|
||||
}
|
||||
|
||||
private addStyles() {
|
||||
const styleEl = document.createElement('style');
|
||||
styleEl.textContent = `
|
||||
.date-option-container {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.date-input-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.date-input-row input[type="radio"] {
|
||||
margin-right: 8px;
|
||||
}
|
||||
.date-input-row input[type="text"],
|
||||
.date-input-row input[type="number"] {
|
||||
margin-left: 5px;
|
||||
}
|
||||
.date-input-row select {
|
||||
margin-left: 5px;
|
||||
}
|
||||
`;
|
||||
|
||||
this.contentEl.appendChild(styleEl);
|
||||
}
|
||||
|
||||
private setupKeyboardListener() {
|
||||
this.keyboardListener = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Enter' && this.validateInput()) {
|
||||
|
|
@ -257,7 +284,7 @@ export class DateInputModal extends Modal {
|
|||
|
||||
if (validInput) {
|
||||
const dateCount = this.calculateDateCount();
|
||||
this.submitButton.textContent = `Insert ${dateCount} date${dateCount !== 1 ? 's' : ''}`;
|
||||
this.submitButton.textContent = `Insert ${dateCount} Date${dateCount !== 1 ? 's' : ''}`;
|
||||
} else {
|
||||
this.submitButton.textContent = 'Insert';
|
||||
}
|
||||
|
|
|
|||
62
src/main.ts
62
src/main.ts
|
|
@ -1,4 +1,4 @@
|
|||
import { Editor, MarkdownView, Plugin } from 'obsidian';
|
||||
import { MarkdownView, Plugin } from 'obsidian';
|
||||
import { DateInputModal } from './dateInputModal';
|
||||
import { DEFAULT_SETTINGS, PluginSettings } from './types';
|
||||
import { DateRangeExpanderSettingTab } from './settingsTab';
|
||||
|
|
@ -11,32 +11,44 @@ export default class DateRangeExpanderPlugin extends Plugin {
|
|||
dateUtils: DateUtils;
|
||||
|
||||
async onload() {
|
||||
console.log('DateRangeExpander loaded');
|
||||
|
||||
await this.loadSettings();
|
||||
|
||||
|
||||
this.dateUtils = new DateUtils();
|
||||
this.dateRangeExpander = new DateRangeExpander(this.app, this.settings, this.dateUtils);
|
||||
|
||||
|
||||
this.addSettingTab(new DateRangeExpanderSettingTab(this.app, this));
|
||||
|
||||
|
||||
this.addCommand({
|
||||
id: 'insert-expanded-date-range',
|
||||
name: 'Insert',
|
||||
editorCallback: (editor: Editor, view: MarkdownView) => {
|
||||
new DateInputModal(this.app, (rangeInput) => {
|
||||
const dateStartAndEnd = this.dateUtils.getStartAndEndDates(rangeInput);
|
||||
|
||||
if (dateStartAndEnd) {
|
||||
const cursor = editor.getCursor();
|
||||
let insertedDateRange = this.dateRangeExpander.expandDateRange(dateStartAndEnd) + ' ';
|
||||
if (rangeInput.useCallout) {
|
||||
insertedDateRange = this.dateRangeExpander.wrapInCallout(dateStartAndEnd, insertedDateRange);
|
||||
}
|
||||
editor.replaceRange(insertedDateRange, { line: cursor.line, ch: cursor.ch }, cursor);
|
||||
|
||||
const endPos = { line: cursor.line, ch: cursor.ch + insertedDateRange.length };
|
||||
editor.setCursor(endPos);
|
||||
checkCallback: (checking: boolean) => {
|
||||
const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
|
||||
if (markdownView) {
|
||||
if (!checking) {
|
||||
new DateInputModal(this.app, (rangeInput) => {
|
||||
const dateStartAndEnd = this.dateUtils.getStartAndEndDates(rangeInput);
|
||||
|
||||
if (dateStartAndEnd) {
|
||||
const editor = this.getActiveEditor();
|
||||
if (editor) {
|
||||
const cursor = editor.getCursor();
|
||||
let insertedDateRange = this.dateRangeExpander.expandDateRange(dateStartAndEnd) + ' ';
|
||||
if (rangeInput.useCallout) {
|
||||
insertedDateRange = this.dateRangeExpander.wrapInCallout(dateStartAndEnd, insertedDateRange);
|
||||
}
|
||||
editor.replaceRange(insertedDateRange, { line: cursor.line, ch: cursor.ch }, cursor);
|
||||
|
||||
const endPos = { line: cursor.line, ch: cursor.ch + insertedDateRange.length };
|
||||
editor.setCursor(endPos);
|
||||
}
|
||||
}
|
||||
}).open();
|
||||
}
|
||||
}).open();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -44,4 +56,16 @@ export default class DateRangeExpanderPlugin extends Plugin {
|
|||
async loadSettings() { this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); }
|
||||
|
||||
async saveSettings() { await this.saveData(this.settings); }
|
||||
|
||||
onunload() {
|
||||
console.log('DateRangeExpander unloaded');
|
||||
}
|
||||
|
||||
getActiveEditor() {
|
||||
const activeLeaf = this.app.workspace.getActiveViewOfType(MarkdownView);
|
||||
if (activeLeaf) {
|
||||
return activeLeaf.editor;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
import { App, PluginSettingTab, Setting } from 'obsidian';
|
||||
import DateRangeExpanderPlugin from './main';
|
||||
import { DEFAULT_SETTINGS } from './types';
|
||||
import { normalizePath } from 'obsidian';
|
||||
|
||||
export class DateRangeExpanderSettingTab extends PluginSettingTab {
|
||||
plugin: DateRangeExpanderPlugin;
|
||||
|
|
@ -99,7 +98,7 @@ export class DateRangeExpanderSettingTab extends PluginSettingTab {
|
|||
text.setPlaceholder('Enter folder path')
|
||||
.setValue(this.plugin.settings.customFolderPath || '')
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.customFolderPath = normalizePath(value);
|
||||
this.plugin.settings.customFolderPath = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
24
styles.css
24
styles.css
|
|
@ -1,22 +1,8 @@
|
|||
.date-option-container {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
/*
|
||||
|
||||
.date-input-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
This CSS file will be included with your plugin, and
|
||||
available in the app when your plugin is enabled.
|
||||
|
||||
.date-input-row input[type="radio"] {
|
||||
margin-right: 8px;
|
||||
}
|
||||
If your plugin does not need CSS, delete this file.
|
||||
|
||||
.date-input-row input[type="text"],
|
||||
.date-input-row input[type="number"] {
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.date-input-row select {
|
||||
margin-left: 5px;
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue