Compare commits

...

5 commits
0.9.1 ... main

9 changed files with 73 additions and 856 deletions

144
.gitignore vendored
View file

@ -1,136 +1,14 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# vscode
.vscode
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# npm
node_modules
pnpm-lock.yaml
package-lock.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Don't include the compiled main.js file in the repo.
# They should be uploaded to GitHub releases instead.
main.js
# 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.*
# obsidian
data.json

View file

@ -33,8 +33,25 @@ 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, DD, DDD, DDDD, M, MM, MMM, MMMM, Y, YY, YYY, YYYY
- Example: Fri 15 Mar 2024
- 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
- **Date separator**: Character(s) used to separate dates in the sequence
- Default: ", "

642
main.js

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
{
"id": "date-range-expander",
"name": "Date Range Expander",
"version": "0.9.1",
"version": "1.0.2",
"minAppVersion": "1.5.8",
"description": "Quickly add a range of day references given a date duration.",
"author": "Mil",

View file

@ -1,6 +1,6 @@
{
"name": "obsidian-date-range-expander",
"version": "0.9.1",
"version": "1.0.2",
"description": "Quickly add a range of day references given a date duration.",
"main": "main.js",
"scripts": {

View file

@ -29,7 +29,6 @@ export class DateInputModal extends Modal {
const { contentEl } = this;
contentEl.empty();
this.addStyles();
this.setupKeyboardListener();
this.createStartDateInput();
this.createRangeOptions();
@ -93,32 +92,6 @@ 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()) {
@ -284,7 +257,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';
}

View file

@ -1,4 +1,4 @@
import { MarkdownView, Plugin } from 'obsidian';
import { Editor, MarkdownView, Plugin } from 'obsidian';
import { DateInputModal } from './dateInputModal';
import { DEFAULT_SETTINGS, PluginSettings } from './types';
import { DateRangeExpanderSettingTab } from './settingsTab';
@ -11,44 +11,32 @@ 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',
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();
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);
}
return true;
}
}).open();
}
});
}
@ -56,16 +44,4 @@ 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;
}
}

View file

@ -1,6 +1,7 @@
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;
@ -98,7 +99,7 @@ export class DateRangeExpanderSettingTab extends PluginSettingTab {
text.setPlaceholder('Enter folder path')
.setValue(this.plugin.settings.customFolderPath || '')
.onChange(async (value) => {
this.plugin.settings.customFolderPath = value;
this.plugin.settings.customFolderPath = normalizePath(value);
await this.plugin.saveSettings();
});
});

View file

@ -1,8 +1,22 @@
/*
.date-option-container {
margin-bottom: 15px;
}
This CSS file will be included with your plugin, and
available in the app when your plugin is enabled.
.date-input-row {
display: flex;
align-items: center;
margin-bottom: 10px;
}
If your plugin does not need CSS, delete this file.
.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;
}