mirror of
https://github.com/alexkurowski/solo-toolkit.git
synced 2026-07-22 05:11:44 +00:00
Inline elements inside tables and callouts (#53)
This commit is contained in:
parent
dd5e281e41
commit
255dc3212a
21 changed files with 296 additions and 171 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "solo-rpg-toolkit",
|
||||
"name": "Solo RPG Toolkit",
|
||||
"version": "0.7.12",
|
||||
"version": "0.7.13",
|
||||
"minAppVersion": "1.5.11",
|
||||
"description": "Random generator tools geared towards solo TTRPG gameplay",
|
||||
"author": "Alex Kurowski",
|
||||
|
|
|
|||
107
package-lock.json
generated
107
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "alexkurowski/solo-toolkit",
|
||||
"version": "0.5.0",
|
||||
"version": "0.7.13",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "alexkurowski/solo-toolkit",
|
||||
"version": "0.4.0",
|
||||
"version": "0.7.13",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@codemirror/language": "^6.10.1",
|
||||
|
|
@ -41,18 +41,26 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@codemirror/state": {
|
||||
"version": "6.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.4.1.tgz",
|
||||
"integrity": "sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A==",
|
||||
"dev": true
|
||||
"version": "6.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.5.0.tgz",
|
||||
"integrity": "sha512-MwBHVK60IiIHDcoMet78lxt6iw5gJOGSbNbOIVBHWVXIH4/Nq1+GQgLLGgI1KlnN86WDXsPudVaqYHKBIx7Eyw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@marijn/find-cluster-break": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@codemirror/view": {
|
||||
"version": "6.26.3",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.26.3.tgz",
|
||||
"integrity": "sha512-gmqxkPALZjkgSxIeeweY/wGQXBfwTUaLs8h7OKtSwfbj9Ct3L11lD+u1sS7XHppxFQoMDiMDp07P9f3I2jWOHw==",
|
||||
"version": "6.38.6",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.38.6.tgz",
|
||||
"integrity": "sha512-qiS0z1bKs5WOvHIAC0Cybmv4AJSkAXgX5aD6Mqd2epSLlVJsQl8NG23jCVouIgkh4All/mrbdsf2UOLFnJw0tw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@codemirror/state": "^6.4.0",
|
||||
"@codemirror/state": "^6.5.0",
|
||||
"crelt": "^1.0.6",
|
||||
"style-mod": "^4.1.0",
|
||||
"w3c-keyname": "^2.2.4"
|
||||
}
|
||||
|
|
@ -537,6 +545,13 @@
|
|||
"@lezer/common": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@marijn/find-cluster-break": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.2.tgz",
|
||||
"integrity": "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@nodelib/fs.scandir": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||
|
|
@ -652,6 +667,7 @@
|
|||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.29.0.tgz",
|
||||
"integrity": "sha512-ruKWTv+x0OOxbzIw9nW5oWlUopvP/IQDjB5ZqmTglLIoDTctLlAJpAQFpNPJP/ZI7hTT9sARBosEfaKbcFuECw==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "5.29.0",
|
||||
"@typescript-eslint/types": "5.29.0",
|
||||
|
|
@ -809,6 +825,7 @@
|
|||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz",
|
||||
"integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
|
|
@ -1030,6 +1047,13 @@
|
|||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/crelt": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz",
|
||||
"integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/cross-spawn": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
||||
|
|
@ -1527,6 +1551,7 @@
|
|||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz",
|
||||
"integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@eslint-community/regexpp": "^4.6.1",
|
||||
|
|
@ -2238,17 +2263,18 @@
|
|||
}
|
||||
},
|
||||
"node_modules/obsidian": {
|
||||
"version": "1.5.7-1",
|
||||
"resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.5.7-1.tgz",
|
||||
"integrity": "sha512-T5ZRuQ1FnfXqEoakTTHVDYvzUEEoT8zSPnQCW31PVgYwG4D4tZCQfKHN2hTz1ifnCe8upvwa6mBTAP2WUA5Vng==",
|
||||
"version": "1.12.3",
|
||||
"resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.12.3.tgz",
|
||||
"integrity": "sha512-HxWqe763dOqzXjnNiHmAJTRERN8KILBSqxDSEqbeSr7W8R8Jxezzbca+nz1LiiqXnMpM8lV2jzAezw3CZ4xNUw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/codemirror": "5.60.8",
|
||||
"moment": "2.29.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@codemirror/state": "^6.0.0",
|
||||
"@codemirror/view": "^6.0.0"
|
||||
"@codemirror/state": "6.5.0",
|
||||
"@codemirror/view": "6.38.6"
|
||||
}
|
||||
},
|
||||
"node_modules/once": {
|
||||
|
|
@ -2685,6 +2711,7 @@
|
|||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz",
|
||||
"integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
|
|
@ -2759,6 +2786,7 @@
|
|||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.8.0.tgz",
|
||||
"integrity": "sha512-KgKQly1pv0l4ltcftP59uQZCi4HUYswCLbTqVZEJu7uLX8CTLyswqMLqLN+2QFz4jCptqWVV4SB7vdxcH2+0kQ==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "7.8.0",
|
||||
"@typescript-eslint/types": "7.8.0",
|
||||
|
|
@ -3013,18 +3041,24 @@
|
|||
}
|
||||
},
|
||||
"@codemirror/state": {
|
||||
"version": "6.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.4.1.tgz",
|
||||
"integrity": "sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A==",
|
||||
"dev": true
|
||||
"version": "6.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.5.0.tgz",
|
||||
"integrity": "sha512-MwBHVK60IiIHDcoMet78lxt6iw5gJOGSbNbOIVBHWVXIH4/Nq1+GQgLLGgI1KlnN86WDXsPudVaqYHKBIx7Eyw==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"requires": {
|
||||
"@marijn/find-cluster-break": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"@codemirror/view": {
|
||||
"version": "6.26.3",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.26.3.tgz",
|
||||
"integrity": "sha512-gmqxkPALZjkgSxIeeweY/wGQXBfwTUaLs8h7OKtSwfbj9Ct3L11lD+u1sS7XHppxFQoMDiMDp07P9f3I2jWOHw==",
|
||||
"version": "6.38.6",
|
||||
"resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.38.6.tgz",
|
||||
"integrity": "sha512-qiS0z1bKs5WOvHIAC0Cybmv4AJSkAXgX5aD6Mqd2epSLlVJsQl8NG23jCVouIgkh4All/mrbdsf2UOLFnJw0tw==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"requires": {
|
||||
"@codemirror/state": "^6.4.0",
|
||||
"@codemirror/state": "^6.5.0",
|
||||
"crelt": "^1.0.6",
|
||||
"style-mod": "^4.1.0",
|
||||
"w3c-keyname": "^2.2.4"
|
||||
}
|
||||
|
|
@ -3279,6 +3313,12 @@
|
|||
"@lezer/common": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"@marijn/find-cluster-break": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.2.tgz",
|
||||
"integrity": "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==",
|
||||
"dev": true
|
||||
},
|
||||
"@nodelib/fs.scandir": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||
|
|
@ -3369,6 +3409,7 @@
|
|||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.29.0.tgz",
|
||||
"integrity": "sha512-ruKWTv+x0OOxbzIw9nW5oWlUopvP/IQDjB5ZqmTglLIoDTctLlAJpAQFpNPJP/ZI7hTT9sARBosEfaKbcFuECw==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/scope-manager": "5.29.0",
|
||||
"@typescript-eslint/types": "5.29.0",
|
||||
|
|
@ -3452,7 +3493,8 @@
|
|||
"version": "8.11.3",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz",
|
||||
"integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==",
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"peer": true
|
||||
},
|
||||
"acorn-jsx": {
|
||||
"version": "5.3.2",
|
||||
|
|
@ -3611,6 +3653,12 @@
|
|||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
|
||||
"dev": true
|
||||
},
|
||||
"crelt": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz",
|
||||
"integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==",
|
||||
"dev": true
|
||||
},
|
||||
"cross-spawn": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
||||
|
|
@ -3884,6 +3932,7 @@
|
|||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz",
|
||||
"integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"requires": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@eslint-community/regexpp": "^4.6.1",
|
||||
|
|
@ -4424,9 +4473,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"obsidian": {
|
||||
"version": "1.5.7-1",
|
||||
"resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.5.7-1.tgz",
|
||||
"integrity": "sha512-T5ZRuQ1FnfXqEoakTTHVDYvzUEEoT8zSPnQCW31PVgYwG4D4tZCQfKHN2hTz1ifnCe8upvwa6mBTAP2WUA5Vng==",
|
||||
"version": "1.12.3",
|
||||
"resolved": "https://registry.npmjs.org/obsidian/-/obsidian-1.12.3.tgz",
|
||||
"integrity": "sha512-HxWqe763dOqzXjnNiHmAJTRERN8KILBSqxDSEqbeSr7W8R8Jxezzbca+nz1LiiqXnMpM8lV2jzAezw3CZ4xNUw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/codemirror": "5.60.8",
|
||||
|
|
@ -4717,7 +4766,8 @@
|
|||
"version": "4.7.4",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz",
|
||||
"integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==",
|
||||
"dev": true
|
||||
"dev": true,
|
||||
"peer": true
|
||||
},
|
||||
"typescript-eslint": {
|
||||
"version": "7.8.0",
|
||||
|
|
@ -4754,6 +4804,7 @@
|
|||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.8.0.tgz",
|
||||
"integrity": "sha512-KgKQly1pv0l4ltcftP59uQZCi4HUYswCLbTqVZEJu7uLX8CTLyswqMLqLN+2QFz4jCptqWVV4SB7vdxcH2+0kQ==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/scope-manager": "7.8.0",
|
||||
"@typescript-eslint/types": "7.8.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "alexkurowski/solo-toolkit",
|
||||
"version": "0.7.12",
|
||||
"version": "0.7.13",
|
||||
"description": "Solo RPG toolkit for Obsidian (https://obsidian.md)",
|
||||
"main": "./dist/api.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ export class ClockWidgetBase implements BaseWidget {
|
|||
centerY: number,
|
||||
size: number,
|
||||
index: number,
|
||||
step: number
|
||||
step: number,
|
||||
): string {
|
||||
const angleA = -index * step + 90;
|
||||
const angleB = (-index - 1) * step + 90;
|
||||
|
|
@ -205,31 +205,31 @@ export class ClockWidgetBase implements BaseWidget {
|
|||
const menu = createMenu([
|
||||
{
|
||||
title: "Advance",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.addValue(1);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Subtract",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.addValue(-1);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
"-",
|
||||
{
|
||||
title: "Fill",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.setValue(this.max);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Reset",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.setValue(0);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
"-",
|
||||
|
|
@ -239,17 +239,17 @@ export class ClockWidgetBase implements BaseWidget {
|
|||
{
|
||||
title: "Default",
|
||||
checked: this.color === "",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.color = "";
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
...KNOWN_COLORS.map((color) => ({
|
||||
title: capitalize(color),
|
||||
checked: this.color === color,
|
||||
onClick: () => {
|
||||
onClick: (event: MouseEvent) => {
|
||||
this.color = color;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
})),
|
||||
],
|
||||
|
|
@ -260,40 +260,40 @@ export class ClockWidgetBase implements BaseWidget {
|
|||
{
|
||||
title: "Default",
|
||||
checked: this.size === SIZE_DEFAULT,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size = SIZE_DEFAULT;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Small",
|
||||
checked: this.size === SIZE_SMALL,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size = SIZE_SMALL;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Large",
|
||||
checked: this.size === SIZE_LARGE,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size = SIZE_LARGE;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
"-",
|
||||
{
|
||||
title: "Increase",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size += 8;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Decrease",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size -= 8;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
@ -317,7 +317,7 @@ export class ClockWidgetBase implements BaseWidget {
|
|||
} else {
|
||||
this.addValue(-1);
|
||||
}
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
};
|
||||
this.btnEl.oncontextmenu = (event) => {
|
||||
event.preventDefault();
|
||||
|
|
|
|||
|
|
@ -56,13 +56,13 @@ export class CountWidgetBase implements BaseWidget {
|
|||
} else {
|
||||
this.addValue(-1);
|
||||
}
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
};
|
||||
this.minusEl.oncontextmenu = (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.addValue(-10);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
};
|
||||
|
||||
this.plusEl.onclick = (event) => {
|
||||
|
|
@ -73,13 +73,13 @@ export class CountWidgetBase implements BaseWidget {
|
|||
} else {
|
||||
this.addValue(1);
|
||||
}
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
};
|
||||
this.plusEl.oncontextmenu = (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.addValue(10);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,9 +71,9 @@ export class CountLimitWidgetBase implements BaseWidget {
|
|||
title: "Add value",
|
||||
subMenu: NUMBERS.map((add: number) => ({
|
||||
title: `+${add}`,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.addValue(add);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
})),
|
||||
},
|
||||
|
|
@ -81,9 +81,9 @@ export class CountLimitWidgetBase implements BaseWidget {
|
|||
title: "Subtract value",
|
||||
subMenu: NUMBERS.map((add: number) => ({
|
||||
title: `-${add}`,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.addValue(-add);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
})),
|
||||
},
|
||||
|
|
@ -91,9 +91,9 @@ export class CountLimitWidgetBase implements BaseWidget {
|
|||
title: "Add max",
|
||||
subMenu: NUMBERS.map((add: number) => ({
|
||||
title: `+${add}`,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.addMax(add);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
})),
|
||||
},
|
||||
|
|
@ -101,40 +101,40 @@ export class CountLimitWidgetBase implements BaseWidget {
|
|||
title: "Subtract max",
|
||||
subMenu: NUMBERS.map((add: number) => ({
|
||||
title: `-${add}`,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.addMax(-add);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
})),
|
||||
},
|
||||
"-",
|
||||
{
|
||||
title: "Reset",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.setValue(this.max);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Drain",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.setValue(0);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
"-",
|
||||
{
|
||||
title: "Make clock",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.prefix = "clock: ";
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Make boxes",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.prefix = "boxes: ";
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
onFocus ? "-" : undefined,
|
||||
|
|
@ -165,7 +165,7 @@ export class CountLimitWidgetBase implements BaseWidget {
|
|||
} else {
|
||||
this.addValue(-1);
|
||||
}
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
};
|
||||
this.minusEl.oncontextmenu = (event) => {
|
||||
event.preventDefault();
|
||||
|
|
@ -175,7 +175,7 @@ export class CountLimitWidgetBase implements BaseWidget {
|
|||
} else {
|
||||
this.addMax(-1);
|
||||
}
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
};
|
||||
|
||||
this.plusEl.onclick = (event) => {
|
||||
|
|
@ -186,7 +186,7 @@ export class CountLimitWidgetBase implements BaseWidget {
|
|||
} else {
|
||||
this.addValue(1);
|
||||
}
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
};
|
||||
this.plusEl.oncontextmenu = (event) => {
|
||||
event.preventDefault();
|
||||
|
|
@ -196,7 +196,7 @@ export class CountLimitWidgetBase implements BaseWidget {
|
|||
} else {
|
||||
this.addMax(1);
|
||||
}
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ export class DiceWidgetBase implements BaseWidget {
|
|||
|
||||
// Split text into parts
|
||||
const [controlWithParams, value] = normalized.split(
|
||||
normalized.includes("=") ? " = " : ": "
|
||||
normalized.includes("=") ? " = " : ": ",
|
||||
);
|
||||
const separator = controlWithParams.includes("|") ? "|" : ",";
|
||||
const params: string[] = controlWithParams.split(separator);
|
||||
|
|
@ -298,17 +298,17 @@ export class DiceWidgetBase implements BaseWidget {
|
|||
{
|
||||
title: "Default",
|
||||
checked: this.color === "",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.color = "";
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
...KNOWN_COLORS.map((color) => ({
|
||||
title: capitalize(color),
|
||||
checked: this.color === color,
|
||||
onClick: () => {
|
||||
onClick: (event: MouseEvent) => {
|
||||
this.color = color;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
})),
|
||||
],
|
||||
|
|
@ -319,40 +319,40 @@ export class DiceWidgetBase implements BaseWidget {
|
|||
{
|
||||
title: "Default",
|
||||
checked: this.size === SIZE_DEFAULT,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size = SIZE_DEFAULT;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Small",
|
||||
checked: this.size === SIZE_SMALL,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size = SIZE_SMALL;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Large",
|
||||
checked: this.size === SIZE_LARGE,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size = SIZE_LARGE;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
"-",
|
||||
{
|
||||
title: "Increase",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size += 8;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Decrease",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size -= 8;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
@ -360,17 +360,17 @@ export class DiceWidgetBase implements BaseWidget {
|
|||
{
|
||||
title: "Show dice",
|
||||
checked: this.explicit,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.toggleExplicit();
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Lock",
|
||||
checked: this.disabled,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.toggleDisable();
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
onFocus ? "-" : undefined,
|
||||
|
|
@ -385,15 +385,15 @@ export class DiceWidgetBase implements BaseWidget {
|
|||
]);
|
||||
|
||||
let i = 0;
|
||||
const reroll = () => {
|
||||
const reroll = (event: MouseEvent) => {
|
||||
this.roll();
|
||||
|
||||
i++;
|
||||
if (rollIntervals[i]) {
|
||||
setTimeout(reroll, rollIntervals[i] * 0.5);
|
||||
setTimeout(() => reroll(event), rollIntervals[i] * 0.5);
|
||||
} else {
|
||||
i = 0;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
rollLock = false;
|
||||
}
|
||||
};
|
||||
|
|
@ -403,7 +403,7 @@ export class DiceWidgetBase implements BaseWidget {
|
|||
if (this.disabled) return;
|
||||
if (rollLock) return;
|
||||
rollLock = true;
|
||||
setTimeout(reroll, rollIntervals[i]);
|
||||
setTimeout(() => reroll(event), rollIntervals[i]);
|
||||
setTimeout(() => {
|
||||
rollLock = false;
|
||||
}, 320);
|
||||
|
|
|
|||
|
|
@ -4,3 +4,4 @@ export * from "./countlimit";
|
|||
export * from "./dice";
|
||||
export * from "./space";
|
||||
export * from "./track";
|
||||
export * from "./utils";
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ type MenuItemOption = {
|
|||
title: string;
|
||||
checked?: boolean;
|
||||
disabled?: boolean;
|
||||
onClick?: () => void;
|
||||
onClick?: (event: MouseEvent) => void;
|
||||
subMenu?: MenuItemBlueprint[];
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -155,31 +155,31 @@ export class TrackWidgetBase implements BaseWidget {
|
|||
const menu = createMenu([
|
||||
{
|
||||
title: "Advance",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.addValue(1);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Subtract",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.addValue(-1);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
"-",
|
||||
{
|
||||
title: "Fill",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.setValueTo(this.max);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Reset",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.setValueTo(0);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
"-",
|
||||
|
|
@ -189,17 +189,17 @@ export class TrackWidgetBase implements BaseWidget {
|
|||
{
|
||||
title: "Default",
|
||||
checked: this.color === "",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.color = "";
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
...KNOWN_COLORS.map((color) => ({
|
||||
title: capitalize(color),
|
||||
checked: this.color === color,
|
||||
onClick: () => {
|
||||
onClick: (event: MouseEvent) => {
|
||||
this.color = color;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
})),
|
||||
],
|
||||
|
|
@ -210,40 +210,40 @@ export class TrackWidgetBase implements BaseWidget {
|
|||
{
|
||||
title: "Default",
|
||||
checked: this.size === SIZE_DEFAULT,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size = SIZE_DEFAULT;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Small",
|
||||
checked: this.size === SIZE_SMALL,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size = SIZE_SMALL;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Large",
|
||||
checked: this.size === SIZE_LARGE,
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size = SIZE_LARGE;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
"-",
|
||||
{
|
||||
title: "Increase",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size += 8;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Decrease",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.size -= 8;
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
@ -254,17 +254,17 @@ export class TrackWidgetBase implements BaseWidget {
|
|||
{
|
||||
title: "Box",
|
||||
checked: this.shape === "boxes",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.shape = "boxes";
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Circle",
|
||||
checked: this.shape === "circles",
|
||||
onClick: () => {
|
||||
onClick: (event) => {
|
||||
this.shape = "circles";
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
@ -288,13 +288,13 @@ export class TrackWidgetBase implements BaseWidget {
|
|||
btnEl.classList.add(
|
||||
"clickable-icon",
|
||||
"srt-track-btn",
|
||||
`srt-track-${this.shape}`
|
||||
`srt-track-${this.shape}`,
|
||||
);
|
||||
btnEl.onclick = (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.setValue(i);
|
||||
onChange?.();
|
||||
onChange?.(event);
|
||||
};
|
||||
setTooltip(btnEl, (i + 1).toString(), { delay: 0 });
|
||||
this.btnEls.push(btnEl);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { Menu, MenuItem } from "obsidian";
|
|||
|
||||
export type DomOptions = {
|
||||
onFocus?: () => void;
|
||||
onChange?: () => void;
|
||||
onChange?: (event?: MouseEvent) => void;
|
||||
};
|
||||
|
||||
export interface BaseWidget {
|
||||
|
|
|
|||
43
src/inline/base/utils.ts
Normal file
43
src/inline/base/utils.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { App, Editor, MarkdownView } from "obsidian";
|
||||
|
||||
type EditorWithPosAtMouse = Editor & {
|
||||
posAtMouse?: (event: MouseEvent) => { line: number; ch: number };
|
||||
};
|
||||
|
||||
const findParentWidgetLines = ({
|
||||
app,
|
||||
event,
|
||||
}: {
|
||||
app: App;
|
||||
event: MouseEvent;
|
||||
}): [number, number] => {
|
||||
let lineStart = -1;
|
||||
let lineEnd = -1;
|
||||
|
||||
// FIXME: read plugins in edit mode don't provide section info, so this is the only
|
||||
// somewhat working solution for finding element position inside the document
|
||||
const view = app.workspace.getActiveViewOfType(MarkdownView);
|
||||
if (view) {
|
||||
const editor = view.editor as EditorWithPosAtMouse;
|
||||
if (editor?.posAtMouse && typeof editor?.posAtMouse === "function") {
|
||||
const position = editor.posAtMouse(event);
|
||||
if (position) {
|
||||
lineStart = position.line;
|
||||
lineEnd = lineStart + 500; // Dunno how many lines the parent element will be, we'll hope for the best here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [lineStart, lineEnd];
|
||||
};
|
||||
|
||||
export const getWidgetLines = (
|
||||
{ lineStart, lineEnd, app }: { lineStart: number; lineEnd: number; app: App },
|
||||
event: MouseEvent,
|
||||
): [number, number] => {
|
||||
if ((lineStart === -1 || lineEnd === -1) && event) {
|
||||
return findParentWidgetLines({ app, event });
|
||||
} else {
|
||||
return [lineStart, lineEnd];
|
||||
}
|
||||
};
|
||||
|
|
@ -72,7 +72,7 @@ class TrackPlugin implements PluginValue {
|
|||
const from = node.from - 1;
|
||||
const to = node.to + 1;
|
||||
|
||||
if (this.isRangeSelected(from, to, selection)) {
|
||||
if (this.isRangeSelected(from + 1, to - 1, selection)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ class TrackPlugin implements PluginValue {
|
|||
originalNode: node.node,
|
||||
originalText: text,
|
||||
}),
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ class TrackPlugin implements PluginValue {
|
|||
originalNode: node.node,
|
||||
originalText: text,
|
||||
}),
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ class TrackPlugin implements PluginValue {
|
|||
originalNode: node.node,
|
||||
originalText: text,
|
||||
}),
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ class TrackPlugin implements PluginValue {
|
|||
originalNode: node.node,
|
||||
originalText: text,
|
||||
}),
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ class TrackPlugin implements PluginValue {
|
|||
originalNode: node.node,
|
||||
originalText: text,
|
||||
}),
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +174,7 @@ class TrackPlugin implements PluginValue {
|
|||
this.spaceStoreIndex[thisWidgetIndex] = width;
|
||||
},
|
||||
}),
|
||||
})
|
||||
}),
|
||||
);
|
||||
widgetIndex++;
|
||||
}
|
||||
|
|
@ -191,10 +191,10 @@ class TrackPlugin implements PluginValue {
|
|||
isRangeSelected(
|
||||
from: number,
|
||||
to: number,
|
||||
selection: EditorSelection
|
||||
selection: EditorSelection,
|
||||
): boolean {
|
||||
return !!selection.ranges.find(
|
||||
(range: SelectionRange) => range.from <= to && range.to >= from
|
||||
(range: SelectionRange) => range.from <= to && range.to >= from,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import { TFile, App } from "obsidian";
|
||||
import { replaceInFile } from "src/utils/plugin";
|
||||
import { ClockWidgetBase, CLOCK_REGEX, CLOCK_REGEX_G } from "../base";
|
||||
import {
|
||||
ClockWidgetBase,
|
||||
CLOCK_REGEX,
|
||||
CLOCK_REGEX_G,
|
||||
getWidgetLines,
|
||||
} from "../base";
|
||||
|
||||
export { CLOCK_REGEX };
|
||||
|
||||
|
|
@ -29,13 +34,15 @@ export class ClockWidget {
|
|||
this.index = opts.index;
|
||||
}
|
||||
|
||||
updateDoc() {
|
||||
updateDoc(event: MouseEvent) {
|
||||
const [lineStart, lineEnd] = getWidgetLines(this, event);
|
||||
|
||||
replaceInFile({
|
||||
vault: this.app.vault,
|
||||
file: this.file,
|
||||
regex: CLOCK_REGEX_G,
|
||||
lineStart: this.lineStart,
|
||||
lineEnd: this.lineEnd,
|
||||
lineStart,
|
||||
lineEnd,
|
||||
newValue: this.base.getText("`"),
|
||||
replaceIndex: this.index,
|
||||
});
|
||||
|
|
@ -43,7 +50,7 @@ export class ClockWidget {
|
|||
|
||||
toDOM(): HTMLElement {
|
||||
this.base.generateDOM({
|
||||
onChange: () => this.updateDoc(),
|
||||
onChange: (event: MouseEvent) => this.updateDoc(event),
|
||||
});
|
||||
|
||||
return this.base.el;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import { TFile, App } from "obsidian";
|
||||
import { replaceInFile } from "src/utils/plugin";
|
||||
import { CountWidgetBase, COUNT_REGEX, COUNT_REGEX_G } from "../base";
|
||||
import {
|
||||
CountWidgetBase,
|
||||
COUNT_REGEX,
|
||||
COUNT_REGEX_G,
|
||||
getWidgetLines,
|
||||
} from "../base";
|
||||
|
||||
export { COUNT_REGEX };
|
||||
|
||||
|
|
@ -29,13 +34,15 @@ export class CountWidget {
|
|||
this.index = opts.index;
|
||||
}
|
||||
|
||||
updateDoc() {
|
||||
updateDoc(event: MouseEvent) {
|
||||
const [lineStart, lineEnd] = getWidgetLines(this, event);
|
||||
|
||||
replaceInFile({
|
||||
vault: this.app.vault,
|
||||
file: this.file,
|
||||
regex: COUNT_REGEX_G,
|
||||
lineStart: this.lineStart,
|
||||
lineEnd: this.lineEnd,
|
||||
lineStart,
|
||||
lineEnd,
|
||||
newValue: this.base.getText("`"),
|
||||
replaceIndex: this.index,
|
||||
});
|
||||
|
|
@ -43,7 +50,7 @@ export class CountWidget {
|
|||
|
||||
toDOM(): HTMLElement {
|
||||
this.base.generateDOM({
|
||||
onChange: () => this.updateDoc(),
|
||||
onChange: (event: MouseEvent) => this.updateDoc(event),
|
||||
});
|
||||
|
||||
return this.base.el;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import {
|
|||
CountLimitWidgetBase,
|
||||
COUNT_LIMIT_REGEX,
|
||||
COUNT_LIMIT_REGEX_G,
|
||||
getWidgetLines,
|
||||
} from "../base";
|
||||
|
||||
export { COUNT_LIMIT_REGEX };
|
||||
|
|
@ -33,13 +34,15 @@ export class CountLimitWidget {
|
|||
this.index = opts.index;
|
||||
}
|
||||
|
||||
updateDoc() {
|
||||
updateDoc(event: MouseEvent) {
|
||||
const [lineStart, lineEnd] = getWidgetLines(this, event);
|
||||
|
||||
replaceInFile({
|
||||
vault: this.app.vault,
|
||||
file: this.file,
|
||||
regex: COUNT_LIMIT_REGEX_G,
|
||||
lineStart: this.lineStart,
|
||||
lineEnd: this.lineEnd,
|
||||
lineStart,
|
||||
lineEnd,
|
||||
newValue: this.base.getText("`"),
|
||||
replaceIndex: this.index,
|
||||
});
|
||||
|
|
@ -47,7 +50,7 @@ export class CountLimitWidget {
|
|||
|
||||
toDOM(): HTMLElement {
|
||||
this.base.generateDOM({
|
||||
onChange: () => this.updateDoc(),
|
||||
onChange: (event: MouseEvent) => this.updateDoc(event),
|
||||
});
|
||||
|
||||
return this.base.el;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import { TFile, App } from "obsidian";
|
||||
import { replaceInFile } from "src/utils/plugin";
|
||||
import { DiceWidgetBase, DICE_REGEX, DICE_REGEX_G } from "../base";
|
||||
import {
|
||||
DiceWidgetBase,
|
||||
DICE_REGEX,
|
||||
DICE_REGEX_G,
|
||||
getWidgetLines,
|
||||
} from "../base";
|
||||
|
||||
export { DICE_REGEX };
|
||||
|
||||
|
|
@ -29,13 +34,15 @@ export class DiceWidget {
|
|||
this.index = opts.index;
|
||||
}
|
||||
|
||||
updateDoc() {
|
||||
updateDoc(event: MouseEvent) {
|
||||
const [lineStart, lineEnd] = getWidgetLines(this, event);
|
||||
|
||||
replaceInFile({
|
||||
vault: this.app.vault,
|
||||
file: this.file,
|
||||
regex: DICE_REGEX_G,
|
||||
lineStart: this.lineStart,
|
||||
lineEnd: this.lineEnd,
|
||||
lineStart,
|
||||
lineEnd,
|
||||
newValue: this.base.getText("`"),
|
||||
replaceIndex: this.index,
|
||||
});
|
||||
|
|
@ -43,7 +50,7 @@ export class DiceWidget {
|
|||
|
||||
toDOM(): HTMLElement {
|
||||
this.base.generateDOM({
|
||||
onChange: () => this.updateDoc(),
|
||||
onChange: (event: MouseEvent) => this.updateDoc(event),
|
||||
});
|
||||
|
||||
return this.base.el;
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ export const soloToolkitPostprocessor = (plugin: Plugin) => {
|
|||
const file = plugin.app.vault.getAbstractFileByPath(ctx.sourcePath);
|
||||
if (!(file instanceof TFile)) return;
|
||||
const section = ctx.getSectionInfo(element);
|
||||
if (!section) return;
|
||||
// if (!section) return;
|
||||
|
||||
const lineStart = section.lineStart;
|
||||
const lineEnd = section.lineEnd;
|
||||
const lineStart = section?.lineStart || -1;
|
||||
const lineEnd = section?.lineEnd || -1;
|
||||
const indexMap = {
|
||||
count: 0,
|
||||
countLimit: 0,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import { App, TFile } from "obsidian";
|
||||
import { replaceInFile } from "src/utils/plugin";
|
||||
import { TrackWidgetBase, TRACK_REGEX, TRACK_REGEX_G } from "../base";
|
||||
import {
|
||||
TrackWidgetBase,
|
||||
TRACK_REGEX,
|
||||
TRACK_REGEX_G,
|
||||
getWidgetLines,
|
||||
} from "../base";
|
||||
|
||||
export { TRACK_REGEX };
|
||||
|
||||
|
|
@ -29,13 +34,15 @@ export class TrackWidget {
|
|||
this.index = opts.index;
|
||||
}
|
||||
|
||||
updateDoc() {
|
||||
updateDoc(event: MouseEvent) {
|
||||
const [lineStart, lineEnd] = getWidgetLines(this, event);
|
||||
|
||||
replaceInFile({
|
||||
vault: this.app.vault,
|
||||
file: this.file,
|
||||
regex: TRACK_REGEX_G,
|
||||
lineStart: this.lineStart,
|
||||
lineEnd: this.lineEnd,
|
||||
lineStart,
|
||||
lineEnd,
|
||||
newValue: this.base.getText("`"),
|
||||
replaceIndex: this.index,
|
||||
});
|
||||
|
|
@ -43,7 +50,7 @@ export class TrackWidget {
|
|||
|
||||
toDOM(): HTMLElement {
|
||||
this.base.generateDOM({
|
||||
onChange: () => this.updateDoc(),
|
||||
onChange: (event: MouseEvent) => this.updateDoc(event),
|
||||
});
|
||||
|
||||
return this.base.el;
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ export const replaceInFile = (opts: {
|
|||
newValue: string;
|
||||
replaceIndex: number;
|
||||
}) => {
|
||||
if (opts.lineStart === -1 || opts.lineEnd === -1) return;
|
||||
|
||||
opts.vault.process(opts.file, (content: string): string => {
|
||||
const lines = content.split("\n");
|
||||
|
||||
const regex = new RegExp(opts.regex, "g");
|
||||
let matchIndex = 0;
|
||||
|
||||
|
|
@ -33,8 +34,6 @@ export const replaceInFile = (opts: {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// console.error("Match index not found")
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ export const parseFileContent = (
|
|||
}
|
||||
}
|
||||
|
||||
// Remove template based on prefix
|
||||
// Remove templates based on prefix
|
||||
if (templates.length && settings.templatePrefix) {
|
||||
const templatesWithPrefix = templates.filter((template) =>
|
||||
template.key.startsWith(settings.templatePrefix)
|
||||
|
|
|
|||
Loading…
Reference in a new issue