From 3894ff4399e1fd0ff38666ee6c0a30a5325ea4d7 Mon Sep 17 00:00:00 2001 From: valentine195 <38669521+valentine195@users.noreply.github.com> Date: Mon, 4 Oct 2021 15:51:40 -0400 Subject: [PATCH] 6.3.3 - CSS updates - Fixed #98 - icon suggester now closes on mobile when an icon is chosen - Fixed #100 - plugin now includes all free font awesome icons --- manifest.json | 2 +- package-lock.json | 41 +++++++++++++++++++++++++-------- package.json | 5 +++- src/assets/main.css | 27 ++++++++++++++++++++++ src/modal/index.ts | 18 +++++++++------ src/settings.ts | 7 ++---- src/util/icons.ts | 56 ++++++++++++++++++++++++++++++++++----------- versions.json | 2 +- 8 files changed, 120 insertions(+), 38 deletions(-) diff --git a/manifest.json b/manifest.json index 67f9a59..6d209a3 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-admonition", "name": "Admonition", - "version": "6.3.2", + "version": "6.3.3", "minAppVersion": "0.11.0", "description": "Admonition block-styled content for Obsidian.md", "author": "Jeremy Valentine", diff --git a/package-lock.json b/package-lock.json index 663e381..2bfc8e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,15 @@ { "name": "obsidian-admonition", - "version": "6.3.1", + "version": "6.3.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "6.3.1", + "version": "6.3.2", "license": "MIT", + "dependencies": { + "@fortawesome/free-brands-svg-icons": "^5.15.4" + }, "devDependencies": { "@fortawesome/fontawesome-svg-core": "^1.2.32", "@fortawesome/free-regular-svg-icons": "^5.15.3", @@ -27,10 +30,9 @@ } }, "node_modules/@fortawesome/fontawesome-common-types": { - "version": "0.2.35", - "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.2.35.tgz", - "integrity": "sha512-IHUfxSEDS9dDGqYwIW7wTN6tn/O8E0n5PcAHz9cAaBoZw6UpG20IG/YM3NNLaGPwPqgjBAFjIURzqoQs3rrtuw==", - "dev": true, + "version": "0.2.36", + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.2.36.tgz", + "integrity": "sha512-a/7BiSgobHAgBWeN7N0w+lAhInrGxksn13uK7231n2m8EDPE3BMCl9NZLTGrj9ZXfCmC6LM0QLqXidIizVQ6yg==", "hasInstallScript": true, "engines": { "node": ">=6" @@ -49,6 +51,18 @@ "node": ">=6" } }, + "node_modules/@fortawesome/free-brands-svg-icons": { + "version": "5.15.4", + "resolved": "https://registry.npmjs.org/@fortawesome/free-brands-svg-icons/-/free-brands-svg-icons-5.15.4.tgz", + "integrity": "sha512-f1witbwycL9cTENJegcmcZRYyawAFbm8+c6IirLmwbbpqz46wyjbQYLuxOc7weXFXfB7QR8/Vd2u5R3q6JYD9g==", + "hasInstallScript": true, + "dependencies": { + "@fortawesome/fontawesome-common-types": "^0.2.36" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/@fortawesome/free-regular-svg-icons": { "version": "5.15.3", "resolved": "https://registry.npmjs.org/@fortawesome/free-regular-svg-icons/-/free-regular-svg-icons-5.15.3.tgz", @@ -902,10 +916,9 @@ }, "dependencies": { "@fortawesome/fontawesome-common-types": { - "version": "0.2.35", - "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.2.35.tgz", - "integrity": "sha512-IHUfxSEDS9dDGqYwIW7wTN6tn/O8E0n5PcAHz9cAaBoZw6UpG20IG/YM3NNLaGPwPqgjBAFjIURzqoQs3rrtuw==", - "dev": true + "version": "0.2.36", + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-0.2.36.tgz", + "integrity": "sha512-a/7BiSgobHAgBWeN7N0w+lAhInrGxksn13uK7231n2m8EDPE3BMCl9NZLTGrj9ZXfCmC6LM0QLqXidIizVQ6yg==" }, "@fortawesome/fontawesome-svg-core": { "version": "1.2.35", @@ -916,6 +929,14 @@ "@fortawesome/fontawesome-common-types": "^0.2.35" } }, + "@fortawesome/free-brands-svg-icons": { + "version": "5.15.4", + "resolved": "https://registry.npmjs.org/@fortawesome/free-brands-svg-icons/-/free-brands-svg-icons-5.15.4.tgz", + "integrity": "sha512-f1witbwycL9cTENJegcmcZRYyawAFbm8+c6IirLmwbbpqz46wyjbQYLuxOc7weXFXfB7QR8/Vd2u5R3q6JYD9g==", + "requires": { + "@fortawesome/fontawesome-common-types": "^0.2.36" + } + }, "@fortawesome/free-regular-svg-icons": { "version": "5.15.3", "resolved": "https://registry.npmjs.org/@fortawesome/free-regular-svg-icons/-/free-regular-svg-icons-5.15.3.tgz", diff --git a/package.json b/package.json index b176e9a..7f3208e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-admonition", - "version": "6.3.2", + "version": "6.3.3", "description": "Admonition block-styled content for Obsidian.md", "main": "main.js", "scripts": { @@ -27,5 +27,8 @@ "rollup-plugin-css-only": "^3.1.0", "tslib": "^2.0.3", "typescript": "^4.0.3" + }, + "dependencies": { + "@fortawesome/free-brands-svg-icons": "^5.15.4" } } diff --git a/src/assets/main.css b/src/assets/main.css index eb3bc88..686039c 100644 --- a/src/assets/main.css +++ b/src/assets/main.css @@ -200,6 +200,33 @@ input.is-invalid { color: #dc3545; } +.suggestion-content.admonition-icon { + display: flex; + align-items: center; + justify-content: space-between; + flex-flow: row wrap; +} + +.suggestion-content.admonition-icon > .suggestion-text.admonition-text { + width: fit-content; +} + +.suggestion-content.admonition-icon + > .suggestion-flair.admonition-suggester-icon { + width: min-content; + position: relative; + top: unset; + left: unset; + right: unset; + bottom: unset; + display: flex; + align-items: center; +} + +.suggestion-content.admonition-icon > .suggestion-note { + width: 100%; +} + .admonition-suggester-icon svg { width: 1em; } diff --git a/src/modal/index.ts b/src/modal/index.ts index 544b09c..b77f1c8 100644 --- a/src/modal/index.ts +++ b/src/modal/index.ts @@ -5,6 +5,7 @@ import { FuzzySuggestModal, Modal, Notice, + Platform, Scope, Setting, SuggestModal, @@ -68,7 +69,7 @@ class Suggester { return false; }); } - chooseSuggestion(evt: KeyboardEvent) { + chooseSuggestion(evt: KeyboardEvent | MouseEvent) { if (!this.items || !this.items.length) return; const currentValue = this.items[this.selectedItem]; if (currentValue) { @@ -111,6 +112,9 @@ class Suggester { if (currentValue) { this.owner.selectSuggestion(currentValue, event); } + if (Platform.isMobile) { + this.chooseSuggestion(event); + } } wrap(value: number, size: number): number { return ((value % size) + size) % size; @@ -280,8 +284,9 @@ export class IconSuggestionModal extends SuggestionModal m[0] === i); if (match) { let element = matchElements[matches.matches.indexOf(match)]; - content.appendChild(element); + text.appendChild(element); element.appendText(item.name.substring(match[0], match[1])); i += match[1] - match[0] - 1; continue; } - content.appendText(item.name[i]); + text.appendText(item.name[i]); } const iconDiv = createDiv("suggestion-flair admonition-suggester-icon"); iconDiv.appendChild(getIconNode(item)); + content.appendChild(iconDiv); content.createDiv({ cls: "suggestion-note", text: getIconModuleName(item) }); - - content.prepend(iconDiv); } getItems() { return this.icons; @@ -554,7 +558,7 @@ ${this.editor.getDoc().getSelection()} .onClick(() => this.close()); b.extraSettingsEl.setAttr("tabindex", 0); b.extraSettingsEl.onkeydown = (evt) => { - evt.key == "Enter" && this.close() + evt.key == "Enter" && this.close(); }; }); } diff --git a/src/settings.ts b/src/settings.ts index 866b4a3..4587b58 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -397,22 +397,19 @@ class SettingsModal extends Modal { text: ")" }); - const titleSetting = new Setting(settingDiv) + new Setting(settingDiv) .setName(t("Admonition Title")) .setDesc( t("This will be the default title for this admonition type.") ) .addText((text) => { - typeText = text; - typeText.setValue(this.title).onChange((v) => { + text.setValue(this.title).onChange((v) => { if (!v.length) { this.title = null; this.updateTitle(admonitionPreview, this.type); return; } - SettingsModal.removeValidationError(text); - this.title = v; this.updateTitle(admonitionPreview, this.title); }); diff --git a/src/util/icons.ts b/src/util/icons.ts index d8dacbc..4817084 100644 --- a/src/util/icons.ts +++ b/src/util/icons.ts @@ -1,5 +1,6 @@ -import { faCopy } from "@fortawesome/free-regular-svg-icons"; +import { faCopy, far } from "@fortawesome/free-regular-svg-icons"; import { fas } from "@fortawesome/free-solid-svg-icons"; +import { fab } from "@fortawesome/free-brands-svg-icons"; import { IconDefinition, IconName, @@ -11,7 +12,7 @@ import { import { RPG } from "./rpgawesome"; import { AdmonitionIconDefinition, RPGIconName } from "src/@types"; -library.add(fas, faCopy); +library.add(fas, far, fab, faCopy); export const COPY_BUTTON_ICON = icon( findIconDefinition({ @@ -42,12 +43,14 @@ const RPGIconNames: Map = }) ); const FontAwesomeIconNames: Map = new Map( - Object.values(fas).map((i: IconDefinition) => { - return [ - i.iconName, - { name: i.iconName, type: "font-awesome" as "font-awesome" } - ]; - }) + [Object.values(fas), Object.values(far), Object.values(fab)] + .flat() + .map((i: IconDefinition) => { + return [ + i.iconName, + { name: i.iconName, type: "font-awesome" as "font-awesome" } + ]; + }) ); export const iconDefinitions = [ @@ -58,6 +61,10 @@ export const iconDefinitions = [ export function getIconType(str: string): "rpg" | "font-awesome" { if (findIconDefinition({ iconName: str as IconName, prefix: "fas" })) return "font-awesome"; + if (findIconDefinition({ iconName: str as IconName, prefix: "far" })) + return "font-awesome"; + if (findIconDefinition({ iconName: str as IconName, prefix: "fab" })) + return "font-awesome"; if (RPG[str as RPGIconName]) return "rpg"; } @@ -79,16 +86,39 @@ export function getIconNode(item: AdmonitionIconDefinition): Element { return el.children[0]; } if ( - !findIconDefinition({ + findIconDefinition({ iconName: item.name as IconName, prefix: "fas" }) ) - return null; - return icon( + return icon( + findIconDefinition({ + iconName: item.name as IconName, + prefix: "fas" + }) + ).node[0]; + if ( findIconDefinition({ iconName: item.name as IconName, - prefix: "fas" + prefix: "far" }) - ).node[0]; + ) + return icon( + findIconDefinition({ + iconName: item.name as IconName, + prefix: "far" + }) + ).node[0]; + if ( + findIconDefinition({ + iconName: item.name as IconName, + prefix: "fab" + }) + ) + return icon( + findIconDefinition({ + iconName: item.name as IconName, + prefix: "fab" + }) + ).node[0]; } diff --git a/versions.json b/versions.json index 1590aed..e8c68d8 100644 --- a/versions.json +++ b/versions.json @@ -12,5 +12,5 @@ "4.4.2": "0.12.2", "5.0.3": "0.12.2", "6.2.10": "0.12.4", - "6.3.2": "0.12.10" + "6.3.3": "0.12.10" } \ No newline at end of file