mirror of
https://github.com/taskgenius/taskgenius-plugin.git
synced 2026-07-22 06:40:25 +00:00
Fixed issues from reviewing
This commit is contained in:
parent
1c1d92abc9
commit
12eaccce99
5 changed files with 69 additions and 68 deletions
|
|
@ -3,7 +3,7 @@ import process from "process";
|
|||
import builtins from 'builtin-modules'
|
||||
|
||||
const banner =
|
||||
`/*
|
||||
`/*
|
||||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||||
if you want to view the source, please visit the github repository of this plugin
|
||||
*/
|
||||
|
|
@ -15,36 +15,42 @@ esbuild.build({
|
|||
banner: {
|
||||
js: banner,
|
||||
},
|
||||
minify: prod ? true : false,
|
||||
entryPoints: ['src/taskProgressBarIndex.ts'],
|
||||
bundle: true,
|
||||
external: [
|
||||
'obsidian',
|
||||
'electron',
|
||||
'@codemirror/autocomplete',
|
||||
'@codemirror/closebrackets',
|
||||
'@codemirror/collab',
|
||||
'@codemirror/commands',
|
||||
'@codemirror/comment',
|
||||
'@codemirror/fold',
|
||||
'@codemirror/gutter',
|
||||
'@codemirror/highlight',
|
||||
'@codemirror/history',
|
||||
'@codemirror/language',
|
||||
'@codemirror/lint',
|
||||
'@codemirror/matchbrackets',
|
||||
'@codemirror/panel',
|
||||
'@codemirror/rangeset',
|
||||
'@codemirror/rectangular-selection',
|
||||
'@codemirror/search',
|
||||
'@codemirror/state',
|
||||
'@codemirror/stream-parser',
|
||||
'@codemirror/text',
|
||||
'@codemirror/tooltip',
|
||||
'@codemirror/view',
|
||||
...builtins],
|
||||
"codemirror",
|
||||
"@codemirror/autocomplete",
|
||||
"@codemirror/closebrackets",
|
||||
"@codemirror/collab",
|
||||
"@codemirror/commands",
|
||||
"@codemirror/comment",
|
||||
"@codemirror/fold",
|
||||
"@codemirror/gutter",
|
||||
"@codemirror/highlight",
|
||||
"@codemirror/history",
|
||||
"@codemirror/language",
|
||||
"@codemirror/lint",
|
||||
"@codemirror/matchbrackets",
|
||||
"@codemirror/panel",
|
||||
"@codemirror/rangeset",
|
||||
"@codemirror/rectangular-selection",
|
||||
"@codemirror/search",
|
||||
"@codemirror/state",
|
||||
"@codemirror/stream-parser",
|
||||
"@codemirror/text",
|
||||
"@codemirror/tooltip",
|
||||
"@codemirror/view",
|
||||
"@lezer/common",
|
||||
"@lezer/lr",
|
||||
"@lezer/highlight",
|
||||
...builtins,
|
||||
],
|
||||
format: 'cjs',
|
||||
watch: !prod,
|
||||
target: 'es2016',
|
||||
target: 'es2018',
|
||||
logLevel: "info",
|
||||
sourcemap: prod ? false : 'inline',
|
||||
treeShaking: true,
|
||||
|
|
|
|||
26
package.json
26
package.json
|
|
@ -12,23 +12,19 @@
|
|||
"author": "Boninall",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@codemirror/autocomplete": "^0.19.9",
|
||||
"@codemirror/commands": "^0.19.0",
|
||||
"@codemirror/fold": "0.19.0",
|
||||
"@codemirror/highlight": "^0.19.0",
|
||||
"@codemirror/history": "^0.19.0",
|
||||
"@codemirror/lang-html": "^0.19.4",
|
||||
"@codemirror/matchbrackets": "^0.19.0",
|
||||
"@codemirror/panel": "^0.19.0",
|
||||
"@codemirror/basic-setup": "^0.19.0",
|
||||
"@codemirror/buildhelper": "^0.1.0",
|
||||
"@codemirror/lang-css": "^0.19.3",
|
||||
"@codemirror/language": "^0.19.3",
|
||||
"@codemirror/autocomplete": "^6.0.0",
|
||||
"@codemirror/commands": "^6.0.0",
|
||||
"@codemirror/lang-html": "^6.0.0",
|
||||
"@codemirror/basic-setup": "^0.20.0",
|
||||
"@codemirror/lang-css": "^6.0.0",
|
||||
"@codemirror/language": "https://github.com/lishid/cm-language",
|
||||
"@codemirror/rangeset": "^0.19.1",
|
||||
"@codemirror/state": "^0.19.9",
|
||||
"@codemirror/view": "^0.19.7",
|
||||
"@codemirror/search": "^0.19.0",
|
||||
"@codemirror/lint": "^6.0.0",
|
||||
"@codemirror/search": "^6.0.0",
|
||||
"@codemirror/state": "^6.0.0",
|
||||
"@codemirror/view": "^6.0.0",
|
||||
"@codemirror/stream-parser": "https://github.com/lishid/stream-parser",
|
||||
"codemirror": "^6.0.0",
|
||||
"@types/node": "^16.11.6",
|
||||
"@typescript-eslint/eslint-plugin": "^5.2.0",
|
||||
"@typescript-eslint/parser": "^5.2.0",
|
||||
|
|
|
|||
|
|
@ -16,9 +16,8 @@ export default class TaskProgressBarPlugin extends Plugin {
|
|||
await this.loadSettings();
|
||||
|
||||
this.addSettingTab(new TaskProgressBarSettingTab(this.app, this));
|
||||
this.registerEditorExtension(taskProgressBarPlugin(this.app));
|
||||
this.registerEditorExtension(taskProgressBarPlugin(this.app, this));
|
||||
|
||||
addTaskProgressBarToHeading = this.settings.addTaskProgressBarToHeading;
|
||||
}
|
||||
|
||||
onunload() {
|
||||
|
|
@ -77,5 +76,3 @@ class TaskProgressBarSettingTab extends PluginSettingTab {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
export let addTaskProgressBarToHeading: boolean;
|
||||
|
|
|
|||
|
|
@ -3,18 +3,16 @@ import {
|
|||
DecorationSet,
|
||||
EditorView,
|
||||
MatchDecorator,
|
||||
PluginField,
|
||||
ViewPlugin,
|
||||
ViewUpdate,
|
||||
WidgetType,
|
||||
} from '@codemirror/view';
|
||||
import { SearchCursor } from "@codemirror/search";
|
||||
import { App, editorLivePreviewField, MarkdownView, Menu, Setting } from 'obsidian';
|
||||
import { App, editorLivePreviewField, MarkdownView, Menu, Plugin, Setting } from 'obsidian';
|
||||
import { EditorState } from "@codemirror/state";
|
||||
import { foldable, syntaxTree } from "@codemirror/language";
|
||||
import { foldable, syntaxTree, tokenClassNodeProp } from "@codemirror/language";
|
||||
import { RegExpCursor } from "./regexp-cursor";
|
||||
import { tokenClassNodeProp } from "@codemirror/stream-parser";
|
||||
import { addTaskProgressBarToHeading } from "./taskProgressBarIndex";
|
||||
import TaskProgressBarPlugin from "./taskProgressBarIndex";
|
||||
|
||||
interface tasks {
|
||||
completed: number;
|
||||
|
|
@ -58,11 +56,7 @@ class TaskProgressBarWidget extends WidgetType {
|
|||
}
|
||||
|
||||
toDOM() {
|
||||
const creaseEl = createSpan('cm-task-progress-bar');
|
||||
// const progressEl = document.createElement('progress');
|
||||
// progressEl.setAttribute('max', this.total.toString());
|
||||
// progressEl.setAttribute('value', this.completed.toString());
|
||||
// progressEl.setAttribute('class', 'progress-bar-inline');
|
||||
const progressBarEl = createSpan('cm-task-progress-bar');
|
||||
const progressBackGroundEl = document.createElement('div');
|
||||
const progressEl = document.createElement('div');
|
||||
const percentage = Math.round(this.completed / this.total * 10000) / 100;
|
||||
|
|
@ -88,10 +82,10 @@ class TaskProgressBarWidget extends WidgetType {
|
|||
progressBackGroundEl.setAttribute('class', 'progress-bar-inline-background');
|
||||
progressEl.setAttribute('class', 'progress-bar-inline');
|
||||
|
||||
creaseEl.appendChild(progressBackGroundEl);
|
||||
progressBarEl.appendChild(progressBackGroundEl);
|
||||
progressBackGroundEl.appendChild(progressEl);
|
||||
|
||||
return creaseEl;
|
||||
return progressBarEl;
|
||||
}
|
||||
|
||||
ignoreEvent() {
|
||||
|
|
@ -99,7 +93,8 @@ class TaskProgressBarWidget extends WidgetType {
|
|||
}
|
||||
}
|
||||
|
||||
export function taskProgressBarPlugin(app: App) {
|
||||
export function taskProgressBarPlugin(app: App, plugin: TaskProgressBarPlugin) {
|
||||
console.log(plugin);
|
||||
return ViewPlugin.fromClass(
|
||||
class {
|
||||
progressDecorations: DecorationSet = Decoration.none;
|
||||
|
|
@ -132,7 +127,7 @@ export function taskProgressBarPlugin(app: App) {
|
|||
console.debug(err);
|
||||
continue;
|
||||
}
|
||||
if (addTaskProgressBarToHeading) {
|
||||
if (plugin?.settings.addTaskProgressBarToHeading) {
|
||||
try {
|
||||
headingCursor = new RegExpCursor(state.doc, "^(#){1,6} ", {}, part.from, part.to);
|
||||
} catch (err) {
|
||||
|
|
@ -153,10 +148,10 @@ export function taskProgressBarPlugin(app: App) {
|
|||
// @ts-ignore
|
||||
allChildrenText = allChildrenText.concat(this.view.state.doc.slice(range.from, range.to).children[i].text);
|
||||
}
|
||||
tasksNum = this.caculateTasksNum(allChildrenText);
|
||||
tasksNum = this.calculateTasksNum(allChildrenText);
|
||||
} else {
|
||||
// @ts-ignore
|
||||
tasksNum = this.caculateTasksNum(this.view.state.doc.slice(range.from, range.to).text);
|
||||
tasksNum = this.calculateTasksNum(this.view.state.doc.slice(range.from, range.to).text);
|
||||
}
|
||||
if (tasksNum?.total === 0) continue;
|
||||
let startDeco = Decoration.widget({ widget: new TaskProgressBarWidget(app, view, headingLine.to, headingLine.to, tasksNum.completed, tasksNum.total) });
|
||||
|
|
@ -178,7 +173,7 @@ export function taskProgressBarPlugin(app: App) {
|
|||
const range = this.calculateRangeForTransform(this.view.state, line.to);
|
||||
if (!range) continue;
|
||||
// @ts-ignore
|
||||
const tasksNum = this.caculateTasksNum(this.view.state.doc.slice(range.from, range.to).text);
|
||||
const tasksNum = this.calculateTasksNum(this.view.state.doc.slice(range.from, range.to).text);
|
||||
if (tasksNum.total === 0) continue;
|
||||
let startDeco = Decoration.widget({ widget: new TaskProgressBarWidget(app, view, line.to, line.to, tasksNum.completed, tasksNum.total) });
|
||||
progressDecos.push(startDeco.range(line.to, line.to));
|
||||
|
|
@ -205,24 +200,29 @@ export function taskProgressBarPlugin(app: App) {
|
|||
return { from: line.from, to: foldRange.to };
|
||||
}
|
||||
|
||||
public caculateTasksNum(textArray: string[]): tasks {
|
||||
public calculateTasksNum(textArray: string[]): tasks {
|
||||
let completed: number = 0;
|
||||
let total: number = 0;
|
||||
if (!textArray) return;
|
||||
for (let i = 0; i < textArray.length; i++) {
|
||||
if (i === 0) continue;
|
||||
if (textArray[i].match(/[\t|\s]+-\s\[(.)\]/)) total++;
|
||||
if (textArray[i].match(/[\t|\s]+-\s\[x\]/)) completed++;
|
||||
if (addTaskProgressBarToHeading) {
|
||||
if (textArray[i].match(/[\t|\s]+-\s\[(x|X)\]/)) completed++;
|
||||
if (plugin?.settings.addTaskProgressBarToHeading) {
|
||||
if (textArray[i].match(/-\s\[(.)\]/)) total++;
|
||||
if (textArray[i].match(/-\s\[x\]/)) completed++;
|
||||
if (textArray[i].match(/-\s\[(x|X)\]/)) completed++;
|
||||
}
|
||||
}
|
||||
return { completed: completed, total: total };
|
||||
};
|
||||
},
|
||||
{
|
||||
provide: PluginField.decorations.from((val) => val.progressDecorations),
|
||||
},
|
||||
provide: plugin => [
|
||||
// these are separated out so that we can set decoration priority
|
||||
// it's also much easier to sort the decorations when they're grouped
|
||||
EditorView.decorations.of(v => v.plugin(plugin)?.progressDecorations || Decoration.none),
|
||||
],
|
||||
}
|
||||
// provide: PluginField.decorations.from((val) => val.progressDecorations),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"1.0.0": "0.9.7",
|
||||
"1.0.1": "0.12.0",
|
||||
"1.0.2": "0.12.0"
|
||||
}
|
||||
"1.0.2": "0.12.0",
|
||||
"1.1.0": "0.12.0",
|
||||
"1.2.0": "0.15.0"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue