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 "1.0.1" have entirely different histories.
7 changed files with 81 additions and 62 deletions
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: ", "
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "date-range-expander",
|
||||
"name": "Date Range Expander",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.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": "1.0.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