Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
exhuma committed Aug 14, 2022
2 parents fa38a0b + 1c945fd commit 9103db4
Show file tree
Hide file tree
Showing 34 changed files with 484 additions and 275 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.231.3/containers/javascript-node
{
"name": "Node.js",
"name": "Schmackhaft",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 16, 14, 12.
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.2.0

- Auto-Focus the "quicksearch" field
- Provide keyboard shortcuts to navigate links when using the quicksearch.

# 1.1.0

- Fix scrolling issue in the settings & help page
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ mozilla: pages bundled_docs
chrome: pages bundled_docs
mkdir -p unpackaged/chrome/src/core
cp -r build/pages/* unpackaged/chrome/
inkscape -w 48 -h 48 public/assets/icon.svg \
inkscape -w 48 -h 48 assets/icon.svg \
-o unpackaged/chrome/assets/icon48.png || \
inkscape -w 48 -h 48 public/assets/icon.svg \
inkscape -w 48 -h 48 assets/icon.svg \
-e unpackaged/chrome/assets/icon48.png
inkscape -w 96 -h 96 public/assets/icon.svg \
inkscape -w 96 -h 96 assets/icon.svg \
-o unpackaged/chrome/assets/icon96.png || \
inkscape -w 96 -h 96 public/assets/icon.svg \
inkscape -w 96 -h 96 assets/icon.svg \
-e unpackaged/chrome/assets/icon96.png
inkscape -w 128 -h 128 public/assets/icon.svg \
inkscape -w 128 -h 128 assets/icon.svg \
-o unpackaged/chrome/assets/icon128.png || \
inkscape -w 128 -h 128 public/assets/icon.svg \
inkscape -w 128 -h 128 assets/icon.svg \
-e unpackaged/chrome/assets/icon128.png
sed -e 's/__version__/$(CURRENT_VERSION)/' \
manifest-chrome.json > unpackaged/chrome/manifest.json
Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
- Add default tags per source
- Replace arrays with sets where possible
- Add a name to each source
- Add default tags to each source
- Deduplicate bookmarks (if more than one source has the same bookmark, it is added with duplicates)
- Is "postcss" still needed?
File renamed without changes
File renamed without changes
215 changes: 133 additions & 82 deletions demo/demo.ts
Original file line number Diff line number Diff line change
@@ -1,113 +1,164 @@
import "../src/components/views/sh-settings";
import "../src/components/components/layout-vsplit";
import "../src/views/sh-settings";
import "../src/components/layout-vsplit";
import { BookmarkSource } from "../src/types";
import { FakeBrowser } from "./fake-browser";
import { Schmackhaft } from "../src/app-schmackhaft";
import { Settings } from "../src/model/settings";
import { SettingsBridge } from "../src/core/settings";
import { Settings as SettingsElement } from "../src/views/sh-settings";

let settingsElementV1 = document.getElementById("SettingsV1") as SettingsBridge;
let settingsElementV2 = document.getElementById("SettingsV2") as SettingsBridge;
settingsElementV2.settings = JSON.stringify({
remoteUrls: [
"https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json",
"https://demo-2.json",
],
enableBrowserBookmarks: true,
version: 2,
});
settingsElementV2.addEventListener("change", (event) => {
console.log(JSON.parse(event.detail["settings"]));
});
/**
* Initialise the HTML elements which are used to play with the component
* settings
*/
function initSettingsUI() {
let settingsElementV1 = document.getElementById(
"SettingsV1"
) as SettingsElement;
let settingsElementV2 = document.getElementById(
"SettingsV2"
) as SettingsElement;
settingsElementV2.settings = JSON.stringify({
remoteUrls: [
"https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json",
"https://demo-2.json",
],
enableBrowserBookmarks: true,
version: 2,
});
settingsElementV2.addEventListener("change", (event) => {
let evt = event as CustomEvent;
console.log(JSON.parse(evt.detail["settings"]));
});

settingsElementV1.settings = JSON.stringify({
remoteUrl:
"https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json",
version: 1,
});
settingsElementV1.settings = JSON.stringify({
remoteUrl:
"https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json",
version: 1,
});
}

let bookmarksElement = document.getElementById("schmackhaft");
/**
* Initialise a core "schmackhaft custom-element"
*/
function initSchmackhaftUI() {
let bookmarksElement = document.getElementById("schmackhaft") as Schmackhaft;

// We can't use the default settings bridge here, because this only works in a
// browser-extension execution context.
let settings = new Settings(
[
{
type: BookmarkSource.HTTP,
settings: {
url: "https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json",
// We can't use the default settings bridge here, because this only works in a
// browser-extension execution context.
let settings = new Settings(
[
{
type: BookmarkSource.HTTP,
settings: {
url: "https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json",
},
},
},
{
type: BookmarkSource.HTTP,
settings: {
url: "https://raw.githubusercontent.com/exhuma/schmackhaft/e6439061eedd24c50e00e8b2374ec50d376bc6e5/docs/examples/external-file.json",
{
type: BookmarkSource.HTTP,
settings: {
url: "https://raw.githubusercontent.com/exhuma/schmackhaft/e6439061eedd24c50e00e8b2374ec50d376bc6e5/docs/examples/external-file.json",
},
},
},
{
type: BookmarkSource.BROWSER,
settings: {},
},
{
type: BookmarkSource.EXTENSION_STORAGE,
settings: {},
},
],
3
);
bookmarksElement.settings = settings.toJson();
bookmarksElement?.addEventListener("settingsChanged", (event) => {
console.log("Settings Changed to:");
console.log(JSON.parse(event.detail["settings"]));
});
bookmarksElement.injections = { getBrowser: async () => new FakeBrowser() };
{
type: BookmarkSource.BROWSER,
settings: {},
},
{
type: BookmarkSource.EXTENSION_STORAGE,
settings: {},
},
],
3
);
bookmarksElement.settings = settings.toJson();
bookmarksElement?.addEventListener("settingsChanged", (event) => {
let evt = event as CustomEvent;
console.log("Settings Changed to:");
console.log(JSON.parse(evt.detail["settings"]));
});
bookmarksElement.injections = { getBrowser: async () => new FakeBrowser() };
}

/**
* Ensure only the div related to the clicked link is visible
* Toggle the visibility of a single element with the "togglable" class.
*
* @param evt A click-event from the browser
* All "togglable" elements will be hidden *except* the one with the given
* SGML-ID
*
* @param id The ID of the element which should become/remain visible.
*/
function toggleDiv(evt) {
let enabledName = evt.target.dataset["div"];
function toggleDiv(id: string): void {
document.querySelectorAll(".toggleable").forEach((element) => {
let currentName = element.id;
let displayValue = enabledName === currentName ? "block" : "none";
element.style.display = displayValue;
let elmt = element as HTMLElement;
let currentName = elmt.id;
let displayValue = id === currentName ? "block" : "none";
elmt.style.display = displayValue;
});
}

document.querySelectorAll(".clickable").forEach((element) => {
element.addEventListener("click", toggleDiv);
});
/**
* Delegate click events to the visibility "toggler". The clicked element *must*
* have the attribute "data-div" with the SGML-ID as value of the element that
* should be displayed.
*
* @param evt A click-event from the browser
*/
function onTabClicked(evt: Event) {
let enabledName = evt.target.dataset["div"];
toggleDiv(enabledName);
}

/**
* Update bookmarks from an external JSON file
*
* @param url The URL from which to fetch the JSON
*/
async function reloadJson(url) {
async function reloadJson(url: string) {
if (url === undefined || url.trim() === "") {
return;
}
let response = await fetch(url);
if (!response.ok) {
console.error(`Unable to fetch ${url} (${response.statusText})`);
return;
}
let text = await response.text();
let bookmarksElement = document.getElementById("schmackhaft");
bookmarksElement.links = text;
let bookmarksElement = document.getElementById("schmackhaft") as Schmackhaft;
let settings = new Settings([
{
type: BookmarkSource.HTTP,
settings: {
url: url,
},
},
]);
bookmarksElement.settings = settings.toJson();
}

document.getElementById("ReloadJsonButton").addEventListener("click", () => {
/**
* Initialise the elements in the demo-page toolbar
*/
function initToolbar() {
document.getElementById("ReloadJsonButton").addEventListener("click", () => {
let txtJsonFile = document.getElementById(
"ExternalJsonFile"
) as HTMLInputElement;
let url = txtJsonFile.value;
reloadJson(url);
});

let txtJsonFile = document.getElementById("ExternalJsonFile");
let url = txtJsonFile.value;
reloadJson(url);
});
txtJsonFile.addEventListener("change", async (evt) => {
let target = evt.target as HTMLInputElement;
let url = target.value;
reloadJson(url);
});

let txtJsonFile = document.getElementById("ExternalJsonFile");
txtJsonFile.addEventListener("change", async (evt) => {
let url = evt.target.value;
reloadJson(url);
});
document.querySelectorAll(".clickable").forEach((element) => {
element.addEventListener("click", onTabClicked);
});
}

document.querySelector(".toggleable").style.display = "block";
/**
* Initialise all UI elements for the demo page
*/
export function initUI() {
initSettingsUI();
initSchmackhaftUI();
initToolbar();
toggleDiv("Bookmarks");
}
9 changes: 9 additions & 0 deletions demo/fake-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ class FakeStorage {
}
}

class FakeTabs {
create(createProperties: { url: string }) {
console.info(`Would open a new tab to the URL ${createProperties.url}`);
}
}

export class FakeBrowser {
tabs: FakeTabs = new FakeTabs();
runtime: any;

get bookmarks() {
return new BookmarkTree();
}
Expand Down
7 changes: 5 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Development Page</title>
<script type="module" src="./demo"></script>
<script type="module" src="../src/components/app-schmackhaft"></script>
<script type="module" src="../src/app-schmackhaft"></script>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
Expand Down Expand Up @@ -180,4 +179,8 @@ <h1>Settings V2</h1>
</div>
</div>
</body>
<script type="module">
import { initUI } from "./demo";
initUI();
</script>
</html>
2 changes: 1 addition & 1 deletion manifest-chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"show_matches": ["http://*/*", "https://*/*"],
"default_popup": "/src/views/action_button/index.html"
},
"permissions": ["activeTab", "storage", "bookmarks"]
"permissions": ["tabs", "activeTab", "storage", "bookmarks"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "schmackhaft",
"version": "1.1.0",
"version": "1.2.0",
"description": "A bookmark manager based on del.icio.us",
"author": "Michel Albert <[email protected]>",
"license": "MIT",
Expand Down
Loading

0 comments on commit 9103db4

Please sign in to comment.