diff --git a/global.d.ts b/global.d.ts
new file mode 100644
index 0000000..f0b88c6
--- /dev/null
+++ b/global.d.ts
@@ -0,0 +1,26 @@
+export interface PluginSettings {
+ preferredDateFormat: string
+ semiAuto: boolean
+ insertDateProperty: boolean
+ lang: 'en' | 'ja' | 'fr' | 'nl' | 'ru' | 'de' | 'pt'
+ dateChar: string
+ scheduledChar: string
+ deadlineChar: string
+ removeTime: boolean
+ gotoShortcut: string
+ completeTaskShortcut: string
+}
+
+declare global {
+ interface LSPluginBaseInfo {
+ id: string
+ mode: 'shadow' | 'iframe'
+ settings: {
+ disabled: boolean
+ [key: string]: any
+ } & PluginSettings
+ [key: string]: any
+ }
+
+ const logseq: LSPluginBaseInfo
+}
diff --git a/package.json b/package.json
index 963146c..d1a9df8 100644
--- a/package.json
+++ b/package.json
@@ -13,7 +13,8 @@
"dev": "npx vite",
"build": "npx tsc && npx vite build",
"preview": "npx vite preview",
- "build:css": "npx tailwindcss -i ./src/tailwind.css -o ./src/output.css"
+ "build:css": "npx tailwindcss -i ./src/tailwind.css -o ./src/output.css",
+ "lint": "npx eslint . --fix"
},
"release": {
"branches": [
diff --git a/src/features/complete-task/index.ts b/src/features/complete-task/index.ts
index 3ce9947..7758da1 100644
--- a/src/features/complete-task/index.ts
+++ b/src/features/complete-task/index.ts
@@ -8,9 +8,10 @@ export const completeTask = (): void => {
key: 'logseq-datenlp-plugin-completetask',
label: '@Complete task',
keybinding: {
- binding: 'mod+shift+d',
+ binding: logseq.settings!.completeTaskShortcut,
},
},
+
async () => {
const currBlk = await logseq.Editor.getCurrentBlock()
if (!currBlk) return
diff --git a/src/features/go-to-date/index.tsx b/src/features/go-to-date/index.tsx
index 1f8f90e..a1b46b2 100644
--- a/src/features/go-to-date/index.tsx
+++ b/src/features/go-to-date/index.tsx
@@ -7,7 +7,7 @@ export const goToDate = (): void => {
{
key: 'logseq-datenlp-plugin-gotodate',
label: '@Goto date using NLP',
- keybinding: { binding: 'mod+g' },
+ keybinding: { binding: logseq.settings!.gotoShortcut },
},
() => {
createRoot(document.getElementById('app')!).render()
diff --git a/src/features/parse/index.ts b/src/features/parse/index.ts
index d37d168..788669e 100644
--- a/src/features/parse/index.ts
+++ b/src/features/parse/index.ts
@@ -27,11 +27,11 @@ export const checkIfChronoObjHasTime = (startObj): string => {
}
}
-const handleMultipleParsedText = (
+const handleMultipleParsedText = async (
chronoBlock: ParsedResult[],
content: string,
options?: { flag: string },
-): string => {
+): Promise => {
let parsedStr = ''
for (let i = 0; i < chronoBlock.length; i++) {
const parsedText = chronoBlock[i]!.text
@@ -39,7 +39,7 @@ const handleMultipleParsedText = (
const parsedEnd = chronoBlock[i]!.end?.date()
if (i === 0) {
if (!options?.flag) {
- const str = semiAutoParse(
+ const str = await semiAutoParse(
content,
chronoBlock,
parsedText,
@@ -48,7 +48,7 @@ const handleMultipleParsedText = (
)
if (str !== '') parsedStr = str
} else {
- const str = manualParse(
+ const str = await manualParse(
options.flag,
content,
chronoBlock,
@@ -61,7 +61,7 @@ const handleMultipleParsedText = (
if (i > 0) {
if (logseq.settings!.insertDateProperty) break
if (!options?.flag) {
- parsedStr = semiAutoParse(
+ parsedStr = await semiAutoParse(
parsedStr,
chronoBlock,
parsedText,
@@ -69,7 +69,7 @@ const handleMultipleParsedText = (
parsedEnd,
)
} else {
- parsedStr = manualParse(
+ parsedStr = await manualParse(
options.flag,
parsedStr,
chronoBlock,
@@ -89,7 +89,6 @@ export const inlineParsing = async (
const { content } = currBlock
const { lang } = logseq.settings!
- // @ts-expect-error Type doesn't match
const chronoBlock: ParsedResult[] = chrono[lang].parse(content, new Date())
if (!chronoBlock || !chronoBlock[0]) return ''
diff --git a/src/features/parse/manual.ts b/src/features/parse/manual.ts
index fcd8122..9b627ab 100644
--- a/src/features/parse/manual.ts
+++ b/src/features/parse/manual.ts
@@ -61,24 +61,33 @@ ${getDeadlineDateDay(parsedStart)}${checkTime}`
}
export const manualParsing = () => {
- logseq.Editor.registerSlashCommand('Parse dates', async (e) => {
- const blk = await logseq.Editor.getBlock(e.uuid)
- if (!blk) return
- const content = await inlineParsing(blk, { flag: 'manual-date' })
- if (content) await logseq.Editor.updateBlock(e.uuid, content)
- })
+ logseq.Editor.registerSlashCommand(
+ 'Parse dates',
+ async (e: { uuid: string }) => {
+ const blk = await logseq.Editor.getBlock(e.uuid)
+ if (!blk) return
+ const content = await inlineParsing(blk, { flag: 'manual-date' })
+ if (content) await logseq.Editor.updateBlock(e.uuid, content)
+ },
+ )
- logseq.Editor.registerSlashCommand('Parse scheduled', async (e) => {
- const blk = await logseq.Editor.getBlock(e.uuid)
- if (!blk) return
- const content = await inlineParsing(blk, { flag: 'manual-scheduled' })
- if (content) await logseq.Editor.updateBlock(e.uuid, content)
- })
+ logseq.Editor.registerSlashCommand(
+ 'Parse scheduled',
+ async (e: { uuid: string }) => {
+ const blk = await logseq.Editor.getBlock(e.uuid)
+ if (!blk) return
+ const content = await inlineParsing(blk, { flag: 'manual-scheduled' })
+ if (content) await logseq.Editor.updateBlock(e.uuid, content)
+ },
+ )
- logseq.Editor.registerSlashCommand('Parse deadline', async (e) => {
- const blk = await logseq.Editor.getBlock(e.uuid)
- if (!blk) return
- const content = await inlineParsing(blk, { flag: 'manual-deadline' })
- if (content) await logseq.Editor.updateBlock(e.uuid, content)
- })
+ logseq.Editor.registerSlashCommand(
+ 'Parse deadline',
+ async (e: { uuid: string }) => {
+ const blk = await logseq.Editor.getBlock(e.uuid)
+ if (!blk) return
+ const content = await inlineParsing(blk, { flag: 'manual-deadline' })
+ if (content) await logseq.Editor.updateBlock(e.uuid, content)
+ },
+ )
}
diff --git a/src/features/parse/semi-auto.ts b/src/features/parse/semi-auto.ts
index a324a37..28fe73e 100644
--- a/src/features/parse/semi-auto.ts
+++ b/src/features/parse/semi-auto.ts
@@ -6,7 +6,6 @@ import {
} from 'logseq-dateutils'
import * as parse from '~/features/parse/index'
-import { PluginSettings } from '~/settings/types'
import { getPreferredDateFormat } from '~/utils'
export const semiAutoParse = async (
@@ -16,8 +15,7 @@ export const semiAutoParse = async (
parsedStart: Date,
parsedEnd: Date | undefined,
): Promise => {
- const { dateChar, scheduledChar, deadlineChar } =
- logseq.settings! as Partial
+ const { dateChar, scheduledChar, deadlineChar } = logseq.settings!
if (!dateChar || !scheduledChar || !deadlineChar) throw new Error()
// handle special characters in code
diff --git a/src/settings/index.ts b/src/settings/index.ts
index 88ca25f..4cc5be4 100644
--- a/src/settings/index.ts
+++ b/src/settings/index.ts
@@ -12,7 +12,7 @@ export const settings: SettingSchemaDesc[] = [
{
key: 'insertDateProperty',
type: 'boolean',
- default: true,
+ default: false,
title: 'Insert Date Property',
description:
'If set to true, when parsing dates, a date property wil be inserted instead of inline.',
@@ -34,6 +34,22 @@ export const settings: SettingSchemaDesc[] = [
title: 'Remove Time',
description: 'Remove time from scheduled and deadline parsing.',
},
+ {
+ key: 'gotoShortcut',
+ type: 'string',
+ default: 'mod+g',
+ title: 'Set shortcut of Go to Date',
+ description:
+ '(Requires restarting Logseq) Modify the shortcut to trigger the pop-up for Go to Date.',
+ },
+ {
+ key: 'completeTaskShortcut',
+ type: 'string',
+ default: 'mod+shift+d',
+ title: 'Set shortcut to Complete Task',
+ description:
+ '(Requires restarting Logseq) Modify the shortcut to mark a task complete.',
+ },
{
key: 'specialCharHeading',
type: 'heading',
diff --git a/src/settings/types.ts b/src/settings/types.ts
deleted file mode 100644
index 1a07fe3..0000000
--- a/src/settings/types.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-export interface PluginSettings {
- preferredDateFormat: string;
- semiAuto: boolean;
- insertDateProperty: boolean;
- lang: "en" | "ja" | "fr" | "nl" | "ru" | "de" | "pt";
- dateChar: string;
- scheduledChar: string;
- deadlineChar: string;
- removeTime: boolean;
-}
diff --git a/tsconfig.json b/tsconfig.json
index 56dc9d7..36be8dd 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -2,7 +2,11 @@
"compilerOptions": {
"jsx": "react-jsx",
"target": "es2017",
- "lib": ["dom", "dom.iterable", "esnext"],
+ "lib": [
+ "dom",
+ "dom.iterable",
+ "esnext"
+ ],
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
@@ -18,10 +22,18 @@
"noUncheckedIndexedAccess": true,
"baseUrl": "./",
"paths": {
- "~/*": ["src/*"]
+ "~/*": [
+ "src/*"
+ ]
}
},
- "include": [".eslintrc.cjs", "**/*.ts", "**/*.tsx", "**/*.cjs", "**/*.mjs"],
+ "include": [
+ "**/*.ts",
+ "**/*.tsx",
+ "**/*.cjs",
+ "**/*.mjs",
+ "global.d.ts"
+ ],
"exclude": [
"node_modules",
"./dist/**/*",