Skip to content

Commit

Permalink
Bring in mProjectsCode major refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeyers committed Feb 1, 2023
1 parent 6b7b03d commit 78204fb
Show file tree
Hide file tree
Showing 52 changed files with 3,716 additions and 2,736 deletions.
43 changes: 43 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
env: {
browser: true,
es6: true,
node: true,
jest: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/member-delimiter-style': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'react/no-unescaped-entities': 'off',
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
'linebreak-style': ['error', 'unix'],
indent: 'off',
quotes: 'off',
},
};
15 changes: 15 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
arrowParens: 'always',
bracketSpacing: true,
endOfLine: 'lf',
htmlWhitespaceSensitivity: 'css',
jsxBracketSameLine: false,
jsxSingleQuote: false,
printWidth: 80,
proseWrap: 'preserve',
quoteProps: 'as-needed',
semi: true,
singleQuote: true,
trailingComma: 'es5',
useTabs: true,
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-style-settings",
"name": "Style Settings",
"version": "0.4.12",
"version": "1.0.0",
"minAppVersion": "0.11.5",
"description": "Offers controls for adjusting theme, plugin, and snippet CSS variables.",
"author": "mgmeyers",
Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"main": "main.js",
"scripts": {
"dev": "rollup --config rollup.config.js -w",
"build": "rollup --config rollup.config.js --environment BUILD:production"
"build": "rollup --config rollup.config.js --environment BUILD:production",
"prettier": "prettier --write \"./src/**/*.{ts,tsx}\"",
"lint": "eslint ./src",
"lint:fix": "eslint ./src --fix",
"clean": "yarn prettier && yarn lint:fix"
},
"keywords": [],
"author": "",
Expand All @@ -15,7 +19,9 @@
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"@types/node": "^14.14.2",
"eslint": "^8.33.0",
"obsidian": "^0.12.17",
"prettier": "^2.8.3",
"rollup": "^2.32.1",
"tslib": "^2.0.3",
"typescript": "^4.0.3"
Expand All @@ -24,6 +30,8 @@
"@simonwep/pickr": "https://github.com/nothingislost/pickr/archive/a17739f7aa1871b44da778cbb79ae76dae77d839.tar.gz",
"@types/chroma-js": "^2.1.3",
"@types/js-yaml": "^4.0.3",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"chroma-js": "^2.1.2",
"detect-indent": "^7.0.0",
"dotenv": "^10.0.0",
Expand Down
155 changes: 83 additions & 72 deletions src/ExportModal.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,83 @@
import {App, Modal, Setting, TextAreaComponent} from "obsidian";
import CSSSettingsPlugin from "./main";
import {SettingValue} from "./SettingsManager";

export class ExportModal extends Modal {
plugin: CSSSettingsPlugin;
section: string;
config: Record<string, SettingValue>;

constructor(app: App, plugin: CSSSettingsPlugin, section: string, config: Record<string, SettingValue>) {
super(app);
this.plugin = plugin;
this.config = config;
this.section = section;
}

onOpen() {
let {contentEl, modalEl} = this;

modalEl.addClass("modal-style-settings");

new Setting(contentEl).setName(`Export settings for: ${this.section}`).then((setting) => {
const output = JSON.stringify(this.config, null, 2);

// Build a copy to clipboard link
setting.controlEl.createEl(
"a",
{
cls: "style-settings-copy",
text: "Copy to clipboard",
href: "#",
},
(copyButton) => {
new TextAreaComponent(contentEl).setValue(output).then((textarea) => {
copyButton.addEventListener("click", (e) => {
e.preventDefault();

// Select the textarea contents and copy them to the clipboard
textarea.inputEl.select();
textarea.inputEl.setSelectionRange(0, 99999);
document.execCommand("copy");

copyButton.addClass("success");

setTimeout(() => {
// If the button is still in the dom, remove the success class
if (copyButton.parentNode) {
copyButton.removeClass("success");
}
}, 2000);
});
});
},
);

// Build a download link
setting.controlEl.createEl("a", {
cls: "style-settings-download",
text: "Download",
attr: {
download: "style-settings.json",
href: `data:application/json;charset=utf-8,${encodeURIComponent(output)}`,
},
});
});
}

onClose() {
let {contentEl} = this;
contentEl.empty();
}
}
import { App, Modal, Setting, TextAreaComponent } from 'obsidian';
import CSSSettingsPlugin from './main';
import { SettingValue } from './SettingsManager';

export class ExportModal extends Modal {
plugin: CSSSettingsPlugin;
section: string;
config: Record<string, SettingValue>;

constructor(
app: App,
plugin: CSSSettingsPlugin,
section: string,
config: Record<string, SettingValue>
) {
super(app);
this.plugin = plugin;
this.config = config;
this.section = section;
}

onOpen() {
const { contentEl, modalEl } = this;

modalEl.addClass('modal-style-settings');

new Setting(contentEl)
.setName(`Export settings for: ${this.section}`)
.then((setting) => {
const output = JSON.stringify(this.config, null, 2);

// Build a copy to clipboard link
setting.controlEl.createEl(
'a',
{
cls: 'style-settings-copy',
text: 'Copy to clipboard',
href: '#',
},
(copyButton) => {
new TextAreaComponent(contentEl)
.setValue(output)
.then((textarea) => {
copyButton.addEventListener('click', (e) => {
e.preventDefault();

// Select the textarea contents and copy them to the clipboard
textarea.inputEl.select();
textarea.inputEl.setSelectionRange(0, 99999);
document.execCommand('copy');

copyButton.addClass('success');

setTimeout(() => {
// If the button is still in the dom, remove the success class
if (copyButton.parentNode) {
copyButton.removeClass('success');
}
}, 2000);
});
});
}
);

// Build a download link
setting.controlEl.createEl('a', {
cls: 'style-settings-download',
text: 'Download',
attr: {
download: 'style-settings.json',
href: `data:application/json;charset=utf-8,${encodeURIComponent(
output
)}`,
},
});
});
}

onClose() {
const { contentEl } = this;
contentEl.empty();
}
}
Loading

0 comments on commit 78204fb

Please sign in to comment.