Skip to content

Fix plugin to run on current versions of Obsidian. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/

main.js
23 changes: 23 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"env": { "node": true },
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
"@typescript-eslint/ban-ts-comment": "off",
"no-prototype-builtins": "off",
"@typescript-eslint/no-empty-function": "off"
}
}
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# vscode
.vscode

# Intellij
*.iml
.idea

# npm
node_modules

# Don't include the compiled main.js file in the repo.
# They should be uploaded to GitHub releases instead.
main.js

# Exclude sourcemaps
*.map

# obsidian
data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tag-version-prefix=""
22 changes: 9 additions & 13 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import esbuild from "esbuild";
import process from "process";
import builtins from 'builtin-modules'
import { writeFileSync } from 'fs';

import builtins from "builtin-modules";

const banner =
`/*
Expand All @@ -13,7 +11,7 @@ if you want to view the source, please visit the github repository of this plugi

const prod = (process.argv[2] === 'production');

const buildConfig = {
const context = await esbuild.context({
banner: {
js: banner,
},
Expand All @@ -33,23 +31,21 @@ const buildConfig = {
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtins
],
...builtins],
format: 'cjs',
target: 'chrome106',
target: 'es2018',
logLevel: "info",
sourcemap: prod ? false : 'inline',
treeShaking: true,
outdir: prod ? 'dist' : '../../dev-vault/.obsidian/plugins/obsidian-confluence',
outdir: prod ? 'dist' : 'dev-dist',
mainFields: ['module', 'main'],
minify: true,
metafile: true,
};
});

if (prod) {
const buildResult = await esbuild.build(buildConfig);
writeFileSync("./dist/meta.json", JSON.stringify(buildResult.metafile));
await context.rebuild();
process.exit(0);
} else {
const context = await esbuild.context(buildConfig);
await context.watch();
}
}
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "confluence-integration",
"name": "Confluence Integration",
"version": "5.5.2",
"version": "5.5.3",
"minAppVersion": "1.0.0",
"description": "This plugin allows you to publish your notes to Confluence",
"author": "andymac4182",
"authorUrl": "https://github.com/andymac4182",
"isDesktopOnly": true
}
}
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
{
"name": "obsidian-confluence",
"version": "5.5.2",
"version": "5.5.3",
"description": "This library allows you to publish your notes to Confluence",
"main": "main.js",
"type": "module",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc && node esbuild.config.mjs production",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"fmt": "npx prettier --write src/",
"lint": "eslint --ignore-path ../../.eslintignore --ext .jsx,tsx,.js,.ts src/",
"prettier-check": "npx prettier --check src/"
"prettier-check": "npx prettier --check src/",
"version": "node version-bump.mjs && git add manifest.json versions.json"
},
"keywords": [],
"author": "andymac4182",
"license": "Apache 2.0",
"devDependencies": {
"@types/mime-types": "^2.1.1",
"@types/react-dom": "^18.0.11",
"obsidian": "1.1.1"
"obsidian": "^1.1.1"
},
"dependencies": {
"confluence.js": "^1.6.3",
"mime-types": "^2.1.35",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"@markdown-confluence/lib": "5.5.2",
"@markdown-confluence/mermaid-electron-renderer": "5.5.2"
},
"resolutions": {
"prosemirror-model": "1.14.3"
"@markdown-confluence/lib": "^5.5.1",
"@markdown-confluence/mermaid-electron-renderer": "^5.5.1",
"@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"builtin-modules": "^3.3.0",
"esbuild": "^0.17.3",
"react": "^18.3.1",
"tslib": "^2.4.0",
"typescript": "^4.7.4"
}
}

154 changes: 78 additions & 76 deletions src/ConfluencePerPageForm.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Modal, App, FrontMatterCache } from "obsidian";
import {Modal, App, FrontMatterCache} from "obsidian";
import ReactDOM from "react-dom";
import React, { useState, ChangeEvent } from "react";
import { ConfluencePageConfig } from "@markdown-confluence/lib";
import { Property } from "csstype";
import React, {useState, ChangeEvent} from "react";
import {ConfluencePageConfig} from "@markdown-confluence/lib";
import {Property} from "csstype";

export type ConfluencePerPageUIValues = {
[K in keyof ConfluencePageConfig.ConfluencePerPageConfig]: {
Expand Down Expand Up @@ -31,7 +31,7 @@ export function mapFrontmatterToConfluencePerPageUIValues(
default: defaultValue,
} = config[
propertyKey as keyof ConfluencePageConfig.ConfluencePerPageConfig
];
];
const frontmatterValue = frontmatter[key];

if (frontmatterValue !== undefined) {
Expand All @@ -44,12 +44,14 @@ export function mapFrontmatterToConfluencePerPageUIValues(
case "options":
case "array-text":
result[propertyKey as keyof ConfluencePerPageUIValues] =
{ value: defaultValue as never, isSet: false };
// @ts-ignore
{value: defaultValue as never, isSet: false};
break;
case "boolean":
case "text":
result[propertyKey as keyof ConfluencePerPageUIValues] =
{ value: undefined, isSet: false };
// @ts-ignore
{value: undefined, isSet: false};
break;
default:
throw new Error("Missing case for inputType");
Expand Down Expand Up @@ -82,14 +84,14 @@ const handleChange = (
) => {
const validationResult = inputValidator(value);

setValues((prevValues) => ({
setValues((prevValues: any) => ({
...prevValues,
[key]: {
...prevValues[key as keyof ConfluencePerPageUIValues],
...(isSetValue ? { isSet: value } : { value }),
...(isSetValue ? {isSet: value} : {value}),
},
}));
setErrors((prevErrors) => ({
setErrors((prevErrors: any) => ({
...prevErrors,
[key]: validationResult.valid ? [] : validationResult.errors,
}));
Expand Down Expand Up @@ -196,7 +198,7 @@ const renderArrayText = (
const newArray = [
...(values[
key as keyof ConfluencePerPageUIValues
].value as unknown as string[]),
].value as unknown as string[]),
];
newArray[index] = e.target.value;
handleChange(
Expand Down Expand Up @@ -411,10 +413,10 @@ const renderOptions = (
);

const ConfluenceForm: React.FC<FormProps> = ({
config,
initialValues,
onSubmit,
}) => {
config,
initialValues,
onSubmit,
}: { config: any, initialValues: any, onSubmit: any }) => {
const [values, setValues] =
useState<ConfluencePerPageUIValues>(initialValues);
const [errors, setErrors] = useState<Record<string, Error[]>>({});
Expand All @@ -429,67 +431,67 @@ const ConfluenceForm: React.FC<FormProps> = ({
<h1>Update Confluence Page Settings</h1>
<table>
<thead>
<tr>
<td>YAML Key</td>
<td>Value</td>
<td>Update</td>
</tr>
<tr>
<td>YAML Key</td>
<td>Value</td>
<td>Update</td>
</tr>
</thead>
<tbody>
{Object.entries(config).map(([key, config]) => {
switch (config.inputType) {
case "text":
return renderTextInput(
key,
config as ConfluencePageConfig.FrontmatterConfig<
string,
"text"
>,
values,
errors,
setValues,
setErrors,
);
case "array-text":
return renderArrayText(
key,
config as ConfluencePageConfig.FrontmatterConfig<
string[],
"array-text"
>,
values,
errors,
setValues,
setErrors,
);
case "boolean":
return renderBoolean(
key,
config as ConfluencePageConfig.FrontmatterConfig<
boolean,
"boolean"
>,
values,
errors,
setValues,
setErrors,
);
case "options":
return renderOptions(
key,
config as ConfluencePageConfig.FrontmatterConfig<
ConfluencePageConfig.PageContentType,
"options"
>,
values,
errors,
setValues,
setErrors,
);
default:
return null;
}
})}
{Object.entries(config).map(([key, config]: [string, any]) => {
switch (config.inputType) {
case "text":
return renderTextInput(
key,
config as ConfluencePageConfig.FrontmatterConfig<
string,
"text"
>,
values,
errors,
setValues,
setErrors,
);
case "array-text":
return renderArrayText(
key,
config as ConfluencePageConfig.FrontmatterConfig<
string[],
"array-text"
>,
values,
errors,
setValues,
setErrors,
);
case "boolean":
return renderBoolean(
key,
config as ConfluencePageConfig.FrontmatterConfig<
boolean,
"boolean"
>,
values,
errors,
setValues,
setErrors,
);
case "options":
return renderOptions(
key,
config as ConfluencePageConfig.FrontmatterConfig<
ConfluencePageConfig.PageContentType,
"options"
>,
values,
errors,
setValues,
setErrors,
);
default:
return null;
}
})}
</tbody>
</table>
<button type="submit">Submit</button>
Expand All @@ -506,7 +508,7 @@ export class ConfluencePerPageForm extends Modal {
}

override onOpen() {
const { contentEl } = this;
const {contentEl} = this;
const test: FormProps = {
...this.modalProps,
onSubmit: (values) => {
Expand All @@ -518,7 +520,7 @@ export class ConfluencePerPageForm extends Modal {
}

override onClose() {
const { contentEl } = this;
const {contentEl} = this;
ReactDOM.unmountComponentAtNode(contentEl);
contentEl.empty();
}
Expand Down
Loading