Compare commits
33 Commits
c3c36504ab
...
master
Author | SHA1 | Date | |
---|---|---|---|
df28d3c411 | |||
bca3049c27 | |||
944e3d2f11 | |||
b00c97d100 | |||
73fcc340f2 | |||
86ae6acc92 | |||
e873ae0396 | |||
3c80ac3125 | |||
db5a363bff | |||
bc6b12afa1 | |||
6424f66732 | |||
b05e2d3c55 | |||
ae5257b2b3 | |||
c3f9529feb | |||
93b272ecb5 | |||
22e6cacd8e | |||
c52e08afa9 | |||
60b238d42e | |||
14dec9ce96 | |||
d67a51f83b | |||
bb1f98761d | |||
0b56f9b1a8 | |||
560828f4a2 | |||
32094f3a79 | |||
d46223c96a | |||
ffe1dd6f9f | |||
311409d36d | |||
31d9f99b77 | |||
7917a628ef | |||
cb6d5cd944 | |||
b54fbe2059 | |||
609ca4d3f5 | |||
e5b0c96434 |
9
Caddyfile
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
https://notes.dev.hibas123.de:443 {
|
||||||
|
proxy / localhost:1234/
|
||||||
|
tls D:\Certs\_wildcard.dev.hibas123.de.pem D:\Certs\_wildcard.dev.hibas123.de-key.pem
|
||||||
|
}
|
||||||
|
|
||||||
|
https://sf.dev.hibas123.de:443 {
|
||||||
|
proxy / localhost:3004/
|
||||||
|
tls D:\Certs\_wildcard.dev.hibas123.de.pem D:\Certs\_wildcard.dev.hibas123.de-key.pem
|
||||||
|
}
|
26
Earthfile
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
VERSION 0.7
|
||||||
|
|
||||||
|
docker-multi:
|
||||||
|
BUILD --platform linux/amd64 --platform linux/arm64 +docker
|
||||||
|
|
||||||
|
build:
|
||||||
|
FROM node:lts
|
||||||
|
WORKDIR /build
|
||||||
|
COPY . .
|
||||||
|
RUN npm config set registry https://npm.hibas123.de
|
||||||
|
RUN npm install
|
||||||
|
RUN npm run build
|
||||||
|
SAVE ARTIFACT dist secure_notes_files
|
||||||
|
|
||||||
|
docker:
|
||||||
|
FROM busybox:1.36
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY --platform=linux/amd64 +build/secure_notes_files /app/
|
||||||
|
|
||||||
|
|
||||||
|
CMD ["busybox", "httpd", "-f", "-v", "-p", "3001", "-h", "/app"]
|
||||||
|
|
||||||
|
ARG EARTHLY_TARGET_TAG
|
||||||
|
ARG TAG=$EARTHLY_TARGET_TAG
|
||||||
|
SAVE IMAGE --push git.hibas.dev/openserver/secure_notes:$TAG
|
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"secure_file_server": "https://sf.dev.hibas123.de",
|
|
||||||
"auth_server": "https://auth.stamm.me",
|
|
||||||
"client_id": "cf699b12-2014-4a61-bb7d-a7e38b197350",
|
|
||||||
"permission": "5c1ed399dc361731340a49d4",
|
|
||||||
"callback_url": "https://notes.dev.hibas123.de"
|
|
||||||
}
|
|
8827
package-lock.json
generated
70
package.json
@ -1,52 +1,44 @@
|
|||||||
{
|
{
|
||||||
"name": "@hibas123/securenotes2",
|
"name": "@hibas123/securenotes2",
|
||||||
"version": "2.0.0-alpha.1",
|
"version": "2.0.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack --mode=production",
|
"build": "parcel build src/index.html",
|
||||||
"watch": "webpack --mode=development --watch",
|
"dev": "parcel src/index.html"
|
||||||
"start": "webpack-dev-server --mode=production",
|
|
||||||
"start:prod": "webpack-dev-server --mode=production",
|
|
||||||
"start:dev": "webpack-dev-server --mode=development"
|
|
||||||
},
|
},
|
||||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"browserslist": [
|
||||||
|
"last 2 Chrome versions"
|
||||||
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hibas123/secure-file-wrapper": "^2.5.0",
|
"@codemirror/commands": "^6.6.0",
|
||||||
"@hibas123/utils": "^2.1.0",
|
"@codemirror/lang-markdown": "^6.2.5",
|
||||||
|
"@hibas123/secure-file-wrapper": "^2.5.3",
|
||||||
|
"@hibas123/theme": "^2.0.7",
|
||||||
|
"@hibas123/utils": "^2.2.18",
|
||||||
"aes-js": "^3.1.2",
|
"aes-js": "^3.1.2",
|
||||||
"feather-icons": "^4.21.0",
|
"codemirror": "^6.0.1",
|
||||||
"idb": "3.0.2",
|
"easymde": "^2.18.0",
|
||||||
"js-sha256": "^0.9.0",
|
"feather-icons": "^4.29.2",
|
||||||
"js-sha512": "^0.8.0",
|
"idb": "^5.0.8",
|
||||||
|
"js-sha256": "^0.11.0",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
"lodash.clonedeep": "^4.5.0",
|
"lodash.clonedeep": "^4.5.0",
|
||||||
"secure-file-wrapper": "git+https://git.stamm.me/OpenServer/OSSecureFileWrapper.git",
|
"parcel": "^2.12.0",
|
||||||
"uikit": "^3.1.5",
|
"preact": "^10.22.0",
|
||||||
"uuid": "^3.3.2"
|
"preact-feather": "^4.2.1",
|
||||||
|
"uuid": "^10.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/lodash.clonedeep": "^4.5.6",
|
"@parcel/packager-raw-url": "2.12.0",
|
||||||
"@types/uikit": "^2.27.7",
|
"@parcel/transformer-sass": "^2.12.0",
|
||||||
"@types/uuid": "^3.4.4",
|
"@parcel/transformer-webmanifest": "^2.12.0",
|
||||||
"copy-webpack-plugin": "^5.0.3",
|
"@types/codemirror": "5.60.15",
|
||||||
"css-loader": "^2.1.1",
|
"@types/lodash.clonedeep": "^4.5.9",
|
||||||
"file-loader": "^3.0.1",
|
"@types/uuid": "^10.0.0",
|
||||||
"html-webpack-plugin": "^3.2.0",
|
"process": "^0.11.10",
|
||||||
"mini-css-extract-plugin": "^0.7.0",
|
"sass": "^1.77.6",
|
||||||
"node-sass": "^4.12.0",
|
"typescript": "^5.5.2"
|
||||||
"preact": "^8.3.1",
|
|
||||||
"preact-svg-loader": "^0.2.1",
|
|
||||||
"sass-loader": "^7.1.0",
|
|
||||||
"style-loader": "^0.23.1",
|
|
||||||
"ts-loader": "^6.0.2",
|
|
||||||
"typescript": "^3.5.1",
|
|
||||||
"webpack": "^4.32.2",
|
|
||||||
"webpack-bundle-analyzer": "^3.3.2",
|
|
||||||
"webpack-cli": "^3.3.2",
|
|
||||||
"webpack-dev-server": "^3.5.0",
|
|
||||||
"webpack-visualizer-plugin": "^0.1.11",
|
|
||||||
"workbox-webpack-plugin": "^4.3.1",
|
|
||||||
"worker-loader": "^2.0.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
3701
pnpm-lock.yaml
generated
Normal file
@ -1,56 +0,0 @@
|
|||||||
{
|
|
||||||
"short_name": "Secure Notes",
|
|
||||||
"name": "Secure Notes",
|
|
||||||
"decription": "A place to store your notes securly",
|
|
||||||
"share_target": {
|
|
||||||
"url_template": "/#/share?title={title}&text={text}&url={url}",
|
|
||||||
"method": "GET",
|
|
||||||
"enctype": "application/x-www-form-urlencoded",
|
|
||||||
"action": "/",
|
|
||||||
"params": {
|
|
||||||
"title": "title",
|
|
||||||
"text": "text",
|
|
||||||
"url": "url"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"icons": [{
|
|
||||||
"src": "notepad16.png",
|
|
||||||
"sizes": "16x16",
|
|
||||||
"type": "image/png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "notepad24.png",
|
|
||||||
"sizes": "24x24",
|
|
||||||
"type": "image/png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "notepad32.png",
|
|
||||||
"sizes": "32x32",
|
|
||||||
"type": "image/png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "notepad64.png",
|
|
||||||
"sizes": "64x64",
|
|
||||||
"type": "image/png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "notepad128.png",
|
|
||||||
"sizes": "128x128",
|
|
||||||
"type": "image/png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "notepad256.png",
|
|
||||||
"sizes": "256x256",
|
|
||||||
"type": "image/png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "notepad512.png",
|
|
||||||
"sizes": "512x512",
|
|
||||||
"type": "image/png"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"start_url": "/",
|
|
||||||
"display": "standalone",
|
|
||||||
"theme_color": "#e188e5",
|
|
||||||
"background_color": "#ffffff"
|
|
||||||
}
|
|
@ -1,121 +0,0 @@
|
|||||||
function log(...params) {
|
|
||||||
console.log.apply(this, [...["%c[SW]: %c", "color: #f4b942;", "color:unset;"], ...params])
|
|
||||||
}
|
|
||||||
|
|
||||||
const CACHE = "offline";
|
|
||||||
|
|
||||||
let precacheFiles = [
|
|
||||||
"/",
|
|
||||||
"/main.js",
|
|
||||||
"/main.css",
|
|
||||||
"/serviceworker.js"
|
|
||||||
]
|
|
||||||
|
|
||||||
//Install stage sets up the cache-array to configure pre-cache content
|
|
||||||
self.addEventListener('install', (evt) => {
|
|
||||||
log('The service worker is being installed.');
|
|
||||||
evt.waitUntil(precache().then(() => {
|
|
||||||
log('Skip waiting on install');
|
|
||||||
}).catch(log).then(() => self.skipWaiting()));
|
|
||||||
});
|
|
||||||
|
|
||||||
//allow sw to control of current page
|
|
||||||
self.addEventListener('activate', (event) => {
|
|
||||||
log('Claiming clients for current page');
|
|
||||||
return self.clients.claim();
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener('message', (event) => {
|
|
||||||
if (event.data === "clear_cache") {
|
|
||||||
log("Clearing cache");
|
|
||||||
caches.delete(CACHE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.data === "update_index") {
|
|
||||||
log("Updating index");
|
|
||||||
event.waitUntil(caches.open(CACHE).then((cache) => {
|
|
||||||
return cache.addAll(["/", "/index.html"]).then(() => {
|
|
||||||
event.ports[0].postMessage("reload");
|
|
||||||
});
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var Types;
|
|
||||||
(function (Types) {
|
|
||||||
Types[Types["CACHE"] = 0] = "CACHE";
|
|
||||||
Types[Types["NOCACHE"] = 1] = "NOCACHE";
|
|
||||||
Types[Types["REFRESH"] = 2] = "REFRESH";
|
|
||||||
})(Types || (Types = {}));
|
|
||||||
|
|
||||||
let rules = [
|
|
||||||
{
|
|
||||||
match: (url) => {
|
|
||||||
return url.indexOf("/api/") >= 0;
|
|
||||||
},
|
|
||||||
type: Types.NOCACHE
|
|
||||||
},
|
|
||||||
{
|
|
||||||
match: (url) => {
|
|
||||||
return url.indexOf("/version_hash") >= 0;
|
|
||||||
},
|
|
||||||
type: Types.NOCACHE
|
|
||||||
},
|
|
||||||
{
|
|
||||||
match: () => {
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
type: Types.REFRESH
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
self.addEventListener('fetch', (evt) => {
|
|
||||||
if (evt.request.method != 'GET') return; // Dont care about POST requests
|
|
||||||
let rule = rules.find(rule => rule.match(evt.request.url));
|
|
||||||
evt.respondWith((async () => {
|
|
||||||
log("Cache:", Types[rule.type]);
|
|
||||||
switch (rule.type) {
|
|
||||||
case Types.CACHE:
|
|
||||||
return fromCache(evt.request);
|
|
||||||
case Types.REFRESH:
|
|
||||||
return refresh(evt.request).then(r => {
|
|
||||||
evt.waitUntil(r.refresh.catch(_ => { }));
|
|
||||||
return r.result;
|
|
||||||
});
|
|
||||||
case Types.NOCACHE:
|
|
||||||
return fetch(evt.request);
|
|
||||||
}
|
|
||||||
})());
|
|
||||||
});
|
|
||||||
|
|
||||||
async function fromCache(request) {
|
|
||||||
let cache = await caches.open(CACHE);
|
|
||||||
let matching = await cache.match(request);
|
|
||||||
if (matching)
|
|
||||||
return matching
|
|
||||||
|
|
||||||
let res = await fetch(request.clone());
|
|
||||||
await cache.put(request, res);
|
|
||||||
return await cache.match(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function refresh(request) {
|
|
||||||
let cache = await caches.open(CACHE);
|
|
||||||
let web = fetch(request.clone()).then(res => {
|
|
||||||
return cache.put(request, res).then(() => {
|
|
||||||
return cache.match(request);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
let matching = await cache.match(request);
|
|
||||||
|
|
||||||
return {
|
|
||||||
result: matching ? matching : web,
|
|
||||||
refresh: web
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function precache() {
|
|
||||||
return caches.open(CACHE).then(function (cache) {
|
|
||||||
return cache.addAll(precacheFiles);
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,12 +1,14 @@
|
|||||||
import { h } from "preact";
|
import { h } from "preact";
|
||||||
import "./add_button.scss";
|
import "./add_button.scss";
|
||||||
import Plus from "feather-icons/dist/icons/plus.svg";
|
import { Plus } from "preact-feather";
|
||||||
export default function AddButton({ onClick }: { onClick: () => void }) {
|
export default function AddButton({ onClick }: { onClick: () => void }) {
|
||||||
return <button
|
return (
|
||||||
title={"add button"}
|
<button
|
||||||
class="add-button-button uk-button-primary uk-border-circle def-shadow"
|
title="add button"
|
||||||
onClick={() => onClick()}
|
class="fab btn-primary"
|
||||||
>
|
onClick={() => onClick()}
|
||||||
<Plus width={undefined} height={undefined} />
|
>
|
||||||
</button>
|
<Plus width={undefined} height={undefined} />
|
||||||
}
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
3
src/components/CodeMirror.scss
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.CodeMirror {
|
||||||
|
height: auto;
|
||||||
|
}
|
62
src/components/CodeMirror.tsx
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import { h } from "preact";
|
||||||
|
import { useEffect, useRef } from "preact/hooks";
|
||||||
|
|
||||||
|
import { EditorView, basicSetup, } from "codemirror";
|
||||||
|
import { EditorState, Text } from "@codemirror/state";
|
||||||
|
import { defaultKeymap } from "@codemirror/commands"
|
||||||
|
|
||||||
|
import { markdown } from "@codemirror/lang-markdown"
|
||||||
|
// import "codemirror/lib/codemirror.css";
|
||||||
|
// import "codemirror/theme/base16-dark.css";
|
||||||
|
|
||||||
|
import "./CodeMirror.scss";
|
||||||
|
import Theme from "../theme";
|
||||||
|
|
||||||
|
interface ICodeMirrorProps {
|
||||||
|
value: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
onSave?: (value: string) => void;
|
||||||
|
onClose?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CodeMirror(props: ICodeMirrorProps) {
|
||||||
|
const ref = useRef<HTMLTextAreaElement>();
|
||||||
|
useEffect(() => {
|
||||||
|
const instance = new EditorView({
|
||||||
|
parent: ref.current,
|
||||||
|
extensions: [
|
||||||
|
basicSetup,
|
||||||
|
markdown(),
|
||||||
|
|
||||||
|
],
|
||||||
|
})
|
||||||
|
// const instance = CM.(ref.current, {
|
||||||
|
// value: props.value,
|
||||||
|
// mode: "markdown",
|
||||||
|
// lineNumbers: true,
|
||||||
|
// lineWrapping: true,
|
||||||
|
// theme: Theme.isDark.value ? "base16-dark" : "default",
|
||||||
|
// viewportMargin: Infinity,
|
||||||
|
// // extraKeys: {
|
||||||
|
// // "Ctrl-S": (cm) => {
|
||||||
|
// // const val = cm.getValue();
|
||||||
|
// // props?.onSave(val);
|
||||||
|
// // },
|
||||||
|
// // Esc: props.onClose,
|
||||||
|
// // },
|
||||||
|
// });
|
||||||
|
|
||||||
|
const state = EditorState.create({
|
||||||
|
doc: Text.of([props.value ?? ""]),
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.setState(state);
|
||||||
|
instance.focus();
|
||||||
|
state.
|
||||||
|
|
||||||
|
instance.on("change", () => props?.onChange(instance.getValue()));
|
||||||
|
|
||||||
|
return () => { };
|
||||||
|
}, [ref]);
|
||||||
|
return <textarea ref={ref}></textarea>;
|
||||||
|
}
|
@ -1,70 +1,79 @@
|
|||||||
import { h, Component } from "preact";
|
import { h, Component } from "preact";
|
||||||
import Notes from "../notes";
|
import Notes from "../notes";
|
||||||
import Refresh from "feather-icons/dist/icons/refresh-cw.svg";
|
import { RefreshCw as Refresh } from "preact-feather";
|
||||||
import "./footer.scss";
|
import "./footer.scss";
|
||||||
import Notifications from "../notifications";
|
import Notifications from "../notifications";
|
||||||
|
|
||||||
export class Footer extends Component<{}, { synced: boolean, syncing: boolean }> {
|
export class Footer extends Component<
|
||||||
constructor(props) {
|
{},
|
||||||
super(props);
|
{ synced: boolean; syncing: boolean }
|
||||||
this.state = { synced: false, syncing: false };
|
> {
|
||||||
this.onSyncedChange = this.onSyncedChange.bind(this);
|
constructor(props) {
|
||||||
this.onSyncChange = this.onSyncChange.bind(this);
|
super(props);
|
||||||
}
|
this.state = { synced: false, syncing: false };
|
||||||
|
this.onSyncedChange = this.onSyncedChange.bind(this);
|
||||||
|
this.onSyncChange = this.onSyncChange.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
async componentWillMount() {
|
async componentWillMount() {
|
||||||
Notes.syncedObservable.subscribe(this.onSyncedChange);
|
Notes.syncedObservable.subscribe(this.onSyncedChange);
|
||||||
Notes.syncObservable.subscribe(this.onSyncChange);
|
Notes.syncObservable.subscribe(this.onSyncChange);
|
||||||
this.setState({ synced: await Notes.isSynced() })
|
this.setState({ synced: await Notes.isSynced() });
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
Notes.syncedObservable.unsubscribe(this.onSyncedChange);
|
Notes.syncedObservable.unsubscribe(this.onSyncedChange);
|
||||||
Notes.syncObservable.unsubscribe(this.onSyncChange);
|
Notes.syncObservable.unsubscribe(this.onSyncChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
onSyncChange(state: boolean) {
|
onSyncChange(state: boolean) {
|
||||||
console.log("sync", state);
|
console.log("sync", state);
|
||||||
this.setState({ syncing: state })
|
this.setState({ syncing: state });
|
||||||
}
|
}
|
||||||
|
|
||||||
onSyncedChange(state: boolean) {
|
onSyncedChange(state: boolean) {
|
||||||
console.log("synced", state);
|
console.log("synced", state);
|
||||||
this.setState({ synced: state })
|
this.setState({ synced: state });
|
||||||
}
|
}
|
||||||
|
|
||||||
onSyncClick() {
|
onSyncClick() {
|
||||||
Notes.sync().then(() => {
|
Notes.sync().then(() => {
|
||||||
Notifications.sendInfo("Finished Synchronisation");
|
Notifications.sendInfo("Finished Synchronisation");
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let extrac = "";
|
let extrac = undefined;
|
||||||
let color;
|
let color;
|
||||||
let text;
|
let text;
|
||||||
if (this.state.syncing) {
|
if (this.state.syncing) {
|
||||||
color = "orange";
|
color = "orange";
|
||||||
text = "syncing";
|
text = "syncing";
|
||||||
extrac = "reloading"
|
extrac = "reloading";
|
||||||
} else {
|
} else {
|
||||||
if (this.state.synced) {
|
if (this.state.synced) {
|
||||||
color = "green";
|
color = "green";
|
||||||
text = "synced";
|
text = "synced";
|
||||||
} else {
|
} else {
|
||||||
color = "red";
|
color = "red";
|
||||||
text = "not synced";
|
text = "not synced";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return <footer class="uk-background-default def-shadow">
|
return (
|
||||||
|
<footer class="elv-8">
|
||||||
<span>
|
<span>
|
||||||
<span class={extrac} ><a onClick={() => this.onSyncClick()} ><Refresh style="height: 1em; width: 1em;"></Refresh></a></span>
|
<span class={extrac}>
|
||||||
<span style={"margin-left: 8px; color:" + color}>{text}</span>
|
<a onClick={() => this.onSyncClick()}>
|
||||||
|
<Refresh style="height: 1em; width: 1em;"></Refresh>
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
<span style={"margin-left: 8px; color:" + color}>{text}</span>
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
Welcome <b>{Notes.name}</b>
|
Welcome <b>{Notes.name}</b>
|
||||||
</span>
|
</span>
|
||||||
</footer>
|
<span style="color: lightgrey;">v2.0.2</span>
|
||||||
}
|
</footer>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -26,7 +26,7 @@ export class Router extends Component<{}, { next?: JSX.Element, current: JSX.Ele
|
|||||||
render() {
|
render() {
|
||||||
let overlay;
|
let overlay;
|
||||||
if (this.state.next) {
|
if (this.state.next) {
|
||||||
overlay = <div class="transition_container transition_slidein uk-background-default" key={this.state.next.key} ref={(elm: HTMLDivElement) => {
|
overlay = <div class="transition_container transition_slidein background-default" key={this.state.next.key} ref={(elm: HTMLDivElement) => {
|
||||||
let lst = () => {
|
let lst = () => {
|
||||||
if (this.state.next)
|
if (this.state.next)
|
||||||
this.setState({ current: this.state.next, next: undefined }, () => {
|
this.setState({ current: this.state.next, next: undefined }, () => {
|
||||||
@ -42,8 +42,8 @@ export class Router extends Component<{}, { next?: JSX.Element, current: JSX.Ele
|
|||||||
{this.state.next}
|
{this.state.next}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
return <div style="position: relative; overflow-x: hidden; width: 100vw; height: 100vh;">
|
return <div style="position: relative; overflow-x: hidden; width: 100vw; height: calc(100vh - 2rem);">
|
||||||
<div class="transition_container uk-background-default" key={this.state.current.key} ref={elm => this.mounted = elm}>
|
<div class="transition_container background-default" key={this.state.current.key} ref={elm => this.mounted = elm}>
|
||||||
{this.state.current}
|
{this.state.current}
|
||||||
</div>
|
</div>
|
||||||
{overlay}
|
{overlay}
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
>button {
|
>button {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
display: block;
|
display: block;
|
||||||
|
background-color: rgb(224, 224, 224);
|
||||||
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
>*:not(:last-child) {
|
>*:not(:last-child) {
|
||||||
|
@ -1,23 +1,31 @@
|
|||||||
@import "../vars.scss";
|
@import "../vars.scss";
|
||||||
|
|
||||||
.reloading { animation: turner 1s infinite linear }
|
.reloading {
|
||||||
|
display: inline-block;
|
||||||
|
animation: turner 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
@keyframes turner{
|
@keyframes turner {
|
||||||
from{ transform: rotate(0deg) }
|
from {
|
||||||
to { transform: rotate(360deg) }
|
transform: rotate(0deg)
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
footer {
|
footer {
|
||||||
z-index: 128;
|
// z-index: 128;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|
||||||
// border-top: 1px solid $border-color;
|
// border-top: 1px solid $border-color;
|
||||||
|
|
||||||
padding: 0.15em !important;
|
padding: 0.15em 1em !important;
|
||||||
}
|
}
|
@ -27,27 +27,24 @@ export class InputModal extends Modal<string> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <Modal.BaseModal modal={this.props.modal}>
|
return <Modal.BaseModal modal={this.props.modal}>
|
||||||
<div class="uk-form-horizontal uk-margin-large">
|
<div>
|
||||||
<div class="uk-margin">
|
<div class="input-group">
|
||||||
<label class="uk-form-label" for={this.rand}>{this.props.modal.fieldname}</label>
|
<label for={this.rand}>{this.props.modal.fieldname}</label>
|
||||||
<div class="uk-form-controls">
|
<input
|
||||||
<input
|
id={this.rand}
|
||||||
class="uk-input"
|
type={this.props.modal.type}
|
||||||
id={this.rand}
|
placeholder={this.props.modal.fieldname}
|
||||||
type={this.props.modal.type}
|
autofocus
|
||||||
placeholder={this.props.modal.fieldname}
|
ref={elm => { this.input = elm; }}
|
||||||
autofocus
|
onKeyDown={evt => {
|
||||||
ref={elm => { this.input = elm; }}
|
if (evt.keyCode === 13) {
|
||||||
onKeyDown={evt => {
|
this.props.modal.result(this.input.value)
|
||||||
if (evt.keyCode === 13) {
|
}
|
||||||
this.props.modal.result(this.input.value)
|
}}
|
||||||
}
|
/>
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="uk-margin" style="text-align: right;">
|
<div class="modal-action">
|
||||||
<button class="uk-button uk-button-primary" style="display: inline-block;" onClick={() => {
|
<button class="btn btn-primary" onClick={() => {
|
||||||
this.props.modal.result(this.input.value);
|
this.props.modal.result(this.input.value);
|
||||||
}}>Enter</button>
|
}}>Enter</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,7 +12,7 @@ export default class LoadingModal extends Modal<undefined> {
|
|||||||
getComponent() {
|
getComponent() {
|
||||||
return <Modal.BaseModal modal={this}>
|
return <Modal.BaseModal modal={this}>
|
||||||
<div style="display: flex; justify-content: center;">
|
<div style="display: flex; justify-content: center;">
|
||||||
<div style="margin: 3rem;" class="uk-spinner uk-icon">
|
<div style="margin: 3rem;" class="">
|
||||||
<svg width="90" height="90" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg" data-svg="spinner"><circle fill="none" stroke="#000" cx="15" cy="15" r="14" style="stroke-width: 0.333333px;"></circle></svg>
|
<svg width="90" height="90" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg" data-svg="spinner"><circle fill="none" stroke="#000" cx="15" cy="15" r="14" style="stroke-width: 0.333333px;"></circle></svg>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
import { Observable } from "@hibas123/utils";
|
import { Observable } from "@hibas123/utils";
|
||||||
import { h, Component } from "preact";
|
import { h, Component } from "preact";
|
||||||
import CloseIcon from "feather-icons/dist/icons/x.svg";
|
import { X } from "preact-feather";
|
||||||
|
|
||||||
export default abstract class Modal<T> {
|
export default abstract class Modal<T> {
|
||||||
// Static
|
// Static
|
||||||
private static modalObservableServer = new Observable<{ modal: Modal<any>, close: boolean }>();
|
private static modalObservableServer = new Observable<{
|
||||||
|
modal: Modal<any>;
|
||||||
|
close: boolean;
|
||||||
|
}>();
|
||||||
public static modalObservable = Modal.modalObservableServer.getPublicApi();
|
public static modalObservable = Modal.modalObservableServer.getPublicApi();
|
||||||
|
|
||||||
|
|
||||||
protected abstract title: string;
|
protected abstract title: string;
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
@ -17,10 +19,8 @@ export default abstract class Modal<T> {
|
|||||||
|
|
||||||
// Protected
|
// Protected
|
||||||
protected result(value: T | null) {
|
protected result(value: T | null) {
|
||||||
if (this.closeOnResult)
|
if (this.closeOnResult) this.close();
|
||||||
this.close()
|
if (this.onResult) this.onResult(value);
|
||||||
if (this.onResult)
|
|
||||||
this.onResult(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Public
|
//Public
|
||||||
@ -35,13 +35,13 @@ export default abstract class Modal<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the modal and waits for result.
|
* Shows the modal and waits for result.
|
||||||
*
|
*
|
||||||
* Call close when successful
|
* Call close when successful
|
||||||
*/
|
*/
|
||||||
public async getResult(close = true) {
|
public async getResult(close = true) {
|
||||||
this.closeOnResult = close;
|
this.closeOnResult = close;
|
||||||
this.show(false);
|
this.show(false);
|
||||||
return new Promise<T | null>((yes) => this.onResult = yes);
|
return new Promise<T | null>((yes) => (this.onResult = yes));
|
||||||
}
|
}
|
||||||
|
|
||||||
public close() {
|
public close() {
|
||||||
@ -50,52 +50,68 @@ export default abstract class Modal<T> {
|
|||||||
|
|
||||||
public abstract getComponent(): JSX.Element;
|
public abstract getComponent(): JSX.Element;
|
||||||
|
|
||||||
public static BaseModal = class BaseModal<T> extends Component<{ modal: Modal<T> }, {}> {
|
public static BaseModal = class BaseModal<T> extends Component<
|
||||||
|
{ modal: Modal<T> },
|
||||||
|
{}
|
||||||
|
> {
|
||||||
render() {
|
render() {
|
||||||
return <div class="modal-container" onClick={(evt) => {
|
return (
|
||||||
let path = evt.composedPath();
|
<div
|
||||||
if (!path.find(e => {
|
class="modal-container"
|
||||||
let s = (e as Element);
|
onClick={(evt) => {
|
||||||
return s.id === "ModalContent";
|
let path = evt.composedPath();
|
||||||
})) {
|
if (
|
||||||
this.props.modal.result(null)
|
!path.find((e) => {
|
||||||
}
|
let s = e as Element;
|
||||||
}} onKeyDown={evt => {
|
return s.id === "ModalContent";
|
||||||
if (evt.keyCode === 27) {
|
})
|
||||||
this.props.modal.result(null)
|
) {
|
||||||
}
|
this.props.modal.result(null);
|
||||||
}}>
|
|
||||||
<div id="ModalContent" class="uk-card uk-card-body uk-card-body" >
|
|
||||||
<div class="modal-title uk-card-title" style="">
|
|
||||||
<h3>{this.props.modal.title}</h3>
|
|
||||||
{/* <div> */}
|
|
||||||
{!this.props.modal.noClose ?
|
|
||||||
<CloseIcon onClick={() => this.props.modal.result(null)} width={undefined} height={undefined} />
|
|
||||||
: undefined
|
|
||||||
}
|
}
|
||||||
{/* </div> */}
|
}}
|
||||||
|
onKeyDown={(evt) => {
|
||||||
|
if (evt.keyCode === 27) {
|
||||||
|
this.props.modal.result(null);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div id="ModalContent" class="modal">
|
||||||
|
<div class="modal-title" style="">
|
||||||
|
<h3>{this.props.modal.title}</h3>
|
||||||
|
{/* <div> */}
|
||||||
|
{!this.props.modal.noClose ? (
|
||||||
|
<X
|
||||||
|
onClick={() => this.props.modal.result(null)}
|
||||||
|
width={undefined}
|
||||||
|
height={undefined}
|
||||||
|
/>
|
||||||
|
) : undefined}
|
||||||
|
{/* </div> */}
|
||||||
|
</div>
|
||||||
|
{this.props.children}
|
||||||
</div>
|
</div>
|
||||||
{this.props.children}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ModalComponent extends Component<{}, { modal: Modal<any> | undefined, component: JSX.Element | undefined }>{
|
export class ModalComponent extends Component<
|
||||||
|
{},
|
||||||
|
{ modal: Modal<any> | undefined; component: JSX.Element | undefined }
|
||||||
|
> {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.onModal = this.onModal.bind(this);
|
this.onModal = this.onModal.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
onModal({ modal, close }: { modal: Modal<any>, close: boolean }) {
|
onModal({ modal, close }: { modal: Modal<any>; close: boolean }) {
|
||||||
if (!close && this.state.modal !== modal) {
|
if (!close && this.state.modal !== modal) {
|
||||||
this.setState({ modal: modal, component: modal.getComponent() })
|
this.setState({ modal: modal, component: modal.getComponent() });
|
||||||
}
|
} else {
|
||||||
else {
|
if (this.state.modal === modal && close)
|
||||||
if (this.state.modal === modal && close) // Only close if the same
|
// Only close if the same
|
||||||
this.setState({ modal: undefined, component: undefined })
|
this.setState({ modal: undefined, component: undefined });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,8 +124,6 @@ export class ModalComponent extends Component<{}, { modal: Modal<any> | undefine
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <div>
|
return <div>{this.state.component}</div>;
|
||||||
{this.state.component}
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,15 +28,13 @@ export class YesNoModal extends Modal<boolean> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <Modal.BaseModal modal={this.props.modal}>
|
return <Modal.BaseModal modal={this.props.modal}>
|
||||||
<div class="uk-margin-large">
|
<div class="modal-action">
|
||||||
<div style="text-align: right;">
|
<button class="btn-primary" onClick={() => {
|
||||||
<button class="uk-button uk-button-primary uk-margin-right" style="display: inline-block;" onClick={() => {
|
this.props.modal.result(false);
|
||||||
this.props.modal.result(false);
|
}}><span style="text-decoration: underline;">N</span>o</button>
|
||||||
}}><span style="text-decoration: underline;">N</span>o</button>
|
<button class="btn-primary" onClick={() => {
|
||||||
<button class="uk-button uk-button-primary" style="display: inline-block;" onClick={() => {
|
this.props.modal.result(true);
|
||||||
this.props.modal.result(true);
|
}}><span style="text-decoration: underline;">Y</span>es</button>
|
||||||
}}><span style="text-decoration: underline;">Y</span>es</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</Modal.BaseModal>
|
</Modal.BaseModal>
|
||||||
}
|
}
|
||||||
|
@ -4,24 +4,25 @@
|
|||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: rgba(0, 0, 0, 0.8);
|
|
||||||
z-index: 32;
|
z-index: 32;
|
||||||
|
animation: darkenBackground .2s linear;
|
||||||
|
background: rgba(0, 0, 0, 0.8)
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-container>.uk-card {
|
@keyframes darkenBackground {
|
||||||
position: absolute;
|
from {
|
||||||
left: 0;
|
background: rgba(0, 0, 0, 0);
|
||||||
right: 0;
|
}
|
||||||
top: 10%;
|
|
||||||
width: 80%;
|
to {
|
||||||
max-width: 800px;
|
background: rgba(0, 0, 0, 0.8);
|
||||||
margin: auto;
|
}
|
||||||
background: white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-title {
|
.modal-title {
|
||||||
display:flex;
|
display: flex;
|
||||||
justify-content:space-between;
|
justify-content: space-between;
|
||||||
|
|
||||||
>svg {
|
>svg {
|
||||||
height: 1em;
|
height: 1em;
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
span {
|
span {
|
||||||
margin-left: 3px;
|
margin-left: 3px;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
@ -56,5 +57,5 @@
|
|||||||
margin-right:var(--notification-margin);
|
margin-right:var(--notification-margin);
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
width: 300px;
|
width: 300px;
|
||||||
}
|
// transition: all .3s;
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
import { h, Component } from "preact";
|
import { h, Component } from "preact";
|
||||||
import Notes from "../notes";
|
|
||||||
|
|
||||||
import "./notifications.scss"
|
import "./notifications.scss"
|
||||||
import Notifications, { MessageType } from "../notifications";
|
import Notifications, { MessageType } from "../notifications";
|
||||||
@ -37,11 +36,11 @@ export default class NotificationsComponent extends Component<{}, {
|
|||||||
this.setState({ notifications: n });
|
this.setState({ notifications: n });
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.removeNot(not);
|
this.removeNot(not);
|
||||||
}, 3000);
|
}, 20000);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeNot(not: { message: string }) {
|
removeNot(not: { message: string }) {
|
||||||
let n = this.state.notifications.slice(0).filter(e => e !== not);
|
let n = this.state.notifications.filter(e => e !== not);
|
||||||
this.setState({ notifications: n });
|
this.setState({ notifications: n });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
src/components/routes/404/index.tsx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { h } from "preact";
|
||||||
|
|
||||||
|
export default function Error404Page() {
|
||||||
|
return <h1>Page not found!</h1>;
|
||||||
|
}
|
66
src/components/routes/settings/Settings.tsx
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
import { h } from "preact";
|
||||||
|
import { Page } from "../../../page";
|
||||||
|
import Theme, { ThemeStates } from "../../../theme";
|
||||||
|
import Navigation from "../../../navigation";
|
||||||
|
import { ArrowLeft } from "preact-feather";
|
||||||
|
|
||||||
|
export default class SettingsPage extends Page<
|
||||||
|
{ state: any },
|
||||||
|
{ vault: string }
|
||||||
|
> {
|
||||||
|
componentWillMount() {}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
let active = Theme.active();
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<header class="header">
|
||||||
|
<div class="header-icon-button" onClick={() => history.back()}>
|
||||||
|
<ArrowLeft height={undefined} width={undefined} />
|
||||||
|
</div>
|
||||||
|
<span onClick={() => Navigation.setPage("/")}>Settings</span>
|
||||||
|
<span></span>
|
||||||
|
</header>
|
||||||
|
<div class="container">
|
||||||
|
<div className="input-group">
|
||||||
|
<label>Select Theme: </label>
|
||||||
|
<select
|
||||||
|
class="inp"
|
||||||
|
onChange={(ev) =>
|
||||||
|
Theme.change(
|
||||||
|
Number((ev.target as HTMLSelectElement).value)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{Object.keys(ThemeStates)
|
||||||
|
.filter((e) => Number.isNaN(Number(e)))
|
||||||
|
.map((e) => (
|
||||||
|
<option
|
||||||
|
selected={ThemeStates[e] === active}
|
||||||
|
value={ThemeStates[e]}
|
||||||
|
>
|
||||||
|
{e.charAt(0).toUpperCase() +
|
||||||
|
e.slice(1).toLowerCase()}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
{/* <option value={ThemeStates.AUTO}>Auto</option>
|
||||||
|
<option value={ThemeStates.LIGHT}>Light</option>
|
||||||
|
<option value={ThemeStates.DARK}>Dark</option> */}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{/* <button class="btn" onClick={() => Theme.toggle()}>Toggle Dark Mode</button> */}
|
||||||
|
<button
|
||||||
|
class="btn"
|
||||||
|
onClick={() =>
|
||||||
|
window.navigator.serviceWorker.controller.postMessage(
|
||||||
|
"message"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Clear cache
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ import Navigation from "../../../navigation";
|
|||||||
export default class SharePage extends Page<{ state: any }, { vault: string }> {
|
export default class SharePage extends Page<{ state: any }, { vault: string }> {
|
||||||
text: string;
|
text: string;
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
let { title, text, url } = Navigation.getQuery() || {} as any;
|
let { title, text, url } = this.props.state;
|
||||||
let note = "";
|
let note = "";
|
||||||
if (title) {
|
if (title) {
|
||||||
note += title + "\n"
|
note += title + "\n"
|
||||||
@ -24,7 +24,9 @@ export default class SharePage extends Page<{ state: any }, { vault: string }> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <VaultsPage state={undefined} selectVault onSelected={vault => {
|
return <VaultsPage state={undefined} selectVault onSelected={vault => {
|
||||||
Navigation.setPage("/vault", { id: vault }, { entry: "true", note: this.text }, true);
|
Navigation.setPage("/", undefined, undefined, true);
|
||||||
|
Navigation.setPage("/vault", { id: vault });
|
||||||
|
Navigation.setPage("/vault", { id: vault }, { entry: "true", note: this.text });
|
||||||
}} />
|
}} />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
src/components/routes/vault/EasyMde.tsx
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { h } from "preact";
|
||||||
|
|
||||||
|
import * as EasyMDE from "easymde";
|
||||||
|
import "easymde/dist/easymde.min.css"
|
||||||
|
// import "./easymde.scss"
|
||||||
|
import { useEffect, useRef } from "preact/hooks";
|
||||||
|
|
||||||
|
export default function EasyMDEPreact(props: { value: string, onChange: (value: string) => void }) {
|
||||||
|
const ref = useRef<HTMLTextAreaElement>();
|
||||||
|
useEffect(() => {
|
||||||
|
const mde = new EasyMDE({
|
||||||
|
element: ref.current,
|
||||||
|
initialValue: props.value
|
||||||
|
})
|
||||||
|
|
||||||
|
mde.codemirror.on("change", () => {
|
||||||
|
props.onChange(mde.value());
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
mde.cleanup();
|
||||||
|
}
|
||||||
|
}, [ref])
|
||||||
|
return <div style="background: white;">
|
||||||
|
<textarea ref={ref}></textarea>
|
||||||
|
</div>
|
||||||
|
}
|
@ -1,192 +1,134 @@
|
|||||||
import { h, Component } from "preact"
|
import { h, Component } from "preact";
|
||||||
import Notes, { IVault, ViewNote } from "../../../notes";
|
import { IVault, ViewNote } from "../../../notes";
|
||||||
import Trash from "feather-icons/dist/icons/trash-2.svg"
|
import { Trash2 as Trash, X, Save } from "preact-feather";
|
||||||
import X from "feather-icons/dist/icons/x.svg"
|
|
||||||
import Save from "feather-icons/dist/icons/save.svg"
|
|
||||||
|
|
||||||
import Navigation from "../../../navigation";
|
// import Navigation from "../../../navigation";
|
||||||
import { YesNoModal } from "../../modals/YesNoModal";
|
import { YesNoModal } from "../../modals/YesNoModal";
|
||||||
import LoadingModal from "../../modals/LoadingModal";
|
|
||||||
import Notifications, { MessageType } from "../../../notifications";
|
import Notifications, { MessageType } from "../../../notifications";
|
||||||
import Modal from "../../modals/Modal";
|
// import CodeMirror from "../../CodeMirror";
|
||||||
|
|
||||||
const minRows = 3;
|
|
||||||
export default class EntryComponent extends Component<{ vault: Promise<IVault>, id: string | undefined, note: string | undefined }, { title: string, changed: boolean }> {
|
|
||||||
old_text: string;
|
import { useEffect, useMemo, useState } from "preact/hooks";
|
||||||
text: string = "";
|
import { usePromise } from "../../../hooks";
|
||||||
|
import EasyMDEPreact from "./EasyMde";
|
||||||
|
|
||||||
|
interface IEntryProps {
|
||||||
vault: IVault;
|
vault: IVault;
|
||||||
lineHeight: number = 24;
|
id?: string;
|
||||||
note: ViewNote;
|
note?: string;
|
||||||
|
}
|
||||||
|
|
||||||
rows: number = minRows;
|
export default function Entry(props: IEntryProps) {
|
||||||
|
const [changed, setChanged] = useState(false);
|
||||||
|
|
||||||
skip_save: boolean = false;
|
const [text, setText] = useState("");
|
||||||
|
const title = useMemo(() => text?.split("\n", 1)[0], [text]);
|
||||||
|
|
||||||
// loading?: LoadingModal;
|
const [loading, error, note] = usePromise(async () => {
|
||||||
|
let note: ViewNote;
|
||||||
|
if (props.id) {
|
||||||
|
note = await props.vault.getNote(props.id);
|
||||||
|
} else {
|
||||||
|
note = props.vault.newNote();
|
||||||
|
if (props.note) {
|
||||||
|
note.__value = props.note;
|
||||||
|
setChanged(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
constructor(props) {
|
if (!note) {
|
||||||
super(props);
|
Notifications.sendNotification("Note not found!", MessageType.ERROR);
|
||||||
this.state = { changed: false, title: "" };
|
history.back();
|
||||||
}
|
} else {
|
||||||
|
setText(note.__value);
|
||||||
|
}
|
||||||
|
|
||||||
private toVault() {
|
return note;
|
||||||
// history.back()
|
}, [props.vault, props.id]);
|
||||||
history.back();
|
|
||||||
// Navigation.setPage("/vault", { id: this.vault.id }, { entry: "false" }, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
async componentWillMount() {
|
if (loading) {
|
||||||
try {
|
return <div>Loading entry</div>;
|
||||||
this.skip_save = false;
|
} else {
|
||||||
// this.loading = new LoadingModal();
|
const save = async () => {
|
||||||
// this.loading.show();
|
try {
|
||||||
|
if (changed) {
|
||||||
this.vault = await this.props.vault;
|
note.__value = text;
|
||||||
let note: ViewNote;
|
await props.vault.saveNote(note);
|
||||||
let changed = false;
|
setChanged(false);
|
||||||
if (this.props.id)
|
|
||||||
note = await this.vault.getNote(this.props.id)
|
|
||||||
else {
|
|
||||||
note = this.vault.newNote();
|
|
||||||
if (this.props.note) {
|
|
||||||
note.__value = this.props.note;
|
|
||||||
changed = true;
|
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
Notifications.sendError(err);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!note) {
|
const del = async () => {
|
||||||
Notifications.sendNotification("Note not found!", MessageType.ERROR);
|
await props.vault.deleteNote(props.id);
|
||||||
// this.toVault()
|
history.back();
|
||||||
} else {
|
};
|
||||||
this.note = note;
|
|
||||||
this.text = note.__value;
|
const close = async () => {
|
||||||
let rows = this.getRows(this.text);
|
if (changed) {
|
||||||
if (rows !== this.rows) {
|
let modal = new YesNoModal("Really want to quit?");
|
||||||
this.rows = rows;
|
let res = await modal.getResult();
|
||||||
|
if (!res) return;
|
||||||
|
}
|
||||||
|
history.back();
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: Add warning on possibly unwanted exit
|
||||||
|
useEffect(() => {
|
||||||
|
const keyevent = (evt: KeyboardEvent) => {
|
||||||
|
if (evt.key === "s" && evt.ctrlKey) {
|
||||||
|
evt.preventDefault();
|
||||||
|
save();
|
||||||
|
return false;
|
||||||
|
} else if (evt.key === "Escape") {
|
||||||
|
evt.preventDefault();
|
||||||
|
close();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
let [title] = this.text.split("\n", 1);
|
return true;
|
||||||
this.setState({ title, changed })
|
};
|
||||||
// if (this.loading)
|
|
||||||
// this.loading.close();
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
Notifications.sendError(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async save() {
|
document.addEventListener("keydown", keyevent);
|
||||||
try {
|
return () => {
|
||||||
if (this.state.changed) {
|
document.removeEventListener("keydown", keyevent);
|
||||||
this.note.__value = this.text;
|
};
|
||||||
await this.vault.saveNote(this.note);
|
});
|
||||||
this.setState({ changed: false })
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
Notifications.sendError(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// async onKeypress(event) {
|
return (
|
||||||
// event = event || window.event;
|
<div>
|
||||||
//
|
<header class="header" style="margin-bottom: 0;">
|
||||||
// }
|
<div class="header-icon-button" onClick={close}>
|
||||||
|
<X height={undefined} width={undefined} />
|
||||||
componentWillUnmount() {
|
</div>
|
||||||
if (!this.skip_save)
|
{changed && (
|
||||||
this.save()
|
<div
|
||||||
}
|
class="header-icon-button"
|
||||||
|
style="margin-left: 0.5em;"
|
||||||
strToNr(value: string) {
|
onClick={save}
|
||||||
let match = value.match(/\d/g)
|
>
|
||||||
return Number(match.join(""))
|
<Save height={undefined} width={undefined} />
|
||||||
}
|
</div>
|
||||||
|
)}
|
||||||
getRows(value: string) {
|
<span>{title}</span>
|
||||||
const lines = (value.match(/\r?\n/g) || '').length + 1
|
<div class="header-icon-button" onClick={del}>
|
||||||
return Math.max(lines + 1, minRows);
|
<Trash height={undefined} width={undefined} />
|
||||||
}
|
</div>
|
||||||
|
</header>
|
||||||
textAreaChange(evt: KeyboardEvent) {
|
<div class="container" style="padding: 0">
|
||||||
if (evt.keyCode === 17 || evt.keyCode === 27) return; //No character, so not relevant for this function
|
<EasyMDEPreact
|
||||||
let target = (evt.target as HTMLTextAreaElement)
|
value={text}
|
||||||
let value = target.value;
|
onChange={(value) => {
|
||||||
|
setChanged(true);
|
||||||
this.text = value;
|
setText(value);
|
||||||
if (!this.state.changed && this.textAreaKeyPress(evt)) this.setState({ changed: true })
|
}}
|
||||||
|
// onSave={save}
|
||||||
let [title] = value.split("\n", 1);
|
// onClose={close}
|
||||||
if (title !== this.state.title)
|
/>
|
||||||
this.setState({ title });
|
</div>
|
||||||
|
|
||||||
let rows = this.getRows(value);
|
|
||||||
if (rows !== this.rows) {
|
|
||||||
target.rows = rows;
|
|
||||||
this.rows = rows;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async exitHandler() {
|
|
||||||
if (this.state.changed) {
|
|
||||||
let modal = new YesNoModal("Really want to quit?");
|
|
||||||
let res = await modal.getResult();
|
|
||||||
if (res === true) {
|
|
||||||
this.skip_save = true;
|
|
||||||
this.toVault();
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
this.toVault()
|
|
||||||
}
|
|
||||||
|
|
||||||
textAreaKeyPress(evt: KeyboardEvent) {
|
|
||||||
if ((evt.keyCode === 83 || evt.keyCode === 13) && evt.ctrlKey) {
|
|
||||||
evt.preventDefault()
|
|
||||||
this.save();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (evt.keyCode === 27) {
|
|
||||||
evt.preventDefault();
|
|
||||||
this.exitHandler();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const save_handler = async () => {
|
|
||||||
await this.save()
|
|
||||||
Navigation.setPage("/vault", { id: this.vault.id }, { entry: "false" }, true);
|
|
||||||
this.toVault()
|
|
||||||
}
|
|
||||||
|
|
||||||
const delete_handler = async () => {
|
|
||||||
await this.vault.deleteNote(this.props.id);
|
|
||||||
this.toVault()
|
|
||||||
}
|
|
||||||
|
|
||||||
return <div>
|
|
||||||
<header class="uk-background-primary">
|
|
||||||
{/* <div> */}
|
|
||||||
<a class="header-icon-button" onClick={() => this.exitHandler()}><X height={undefined} width={undefined} /></a>
|
|
||||||
{this.state.changed ? <a class="header-icon-button" style="margin-left: 0.5em;" onClick={() => save_handler()}><Save height={undefined} width={undefined} /></a> : undefined}
|
|
||||||
{/* </div> */}
|
|
||||||
<h3 style="display:inline" class="button header-title">{this.state.title}</h3>
|
|
||||||
<a class="header-icon-button" onClick={() => delete_handler()}><Trash height={undefined} width={undefined} /></a>
|
|
||||||
</header>
|
|
||||||
<div class="uk-container">
|
|
||||||
<textarea
|
|
||||||
autofocus
|
|
||||||
value={this.text}
|
|
||||||
rows={this.rows}
|
|
||||||
class="doc uk-textarea"
|
|
||||||
style="width:100%;"
|
|
||||||
onKeyDown={evt => this.textAreaKeyPress(evt)}
|
|
||||||
onKeyUp={evt => this.textAreaChange(evt)}
|
|
||||||
ref={elm => {
|
|
||||||
if (elm)
|
|
||||||
setTimeout(() => elm.focus(), 500)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,25 @@
|
|||||||
import { h, Component } from "preact"
|
import { h, Component } from "preact";
|
||||||
import Notes, { IVault, BaseNote } from "../../../notes";
|
import Notes, { IVault, BaseNote } from "../../../notes";
|
||||||
import AddButton from "../../AddButton";
|
import AddButton from "../../AddButton";
|
||||||
import Navigation from "../../../navigation";
|
import Navigation from "../../../navigation";
|
||||||
import ArrowLeft from "feather-icons/dist/icons/arrow-left.svg"
|
import { ArrowLeft, Search } from "preact-feather";
|
||||||
import Search from "feather-icons/dist/icons/search.svg"
|
|
||||||
import ContextMenu from "../../context";
|
import ContextMenu from "../../context";
|
||||||
import Notifications from "../../../notifications";
|
import Notifications from "../../../notifications";
|
||||||
import { Observable, Lock } from "@hibas123/utils";
|
import { Observable, Lock } from "@hibas123/utils";
|
||||||
|
|
||||||
|
export default class EntryList extends Component<
|
||||||
export default class EntryList extends Component<{ vault: Promise<IVault> }, { notes: BaseNote[], context: JSX.Element | undefined }> {
|
{ vault: IVault },
|
||||||
|
{ notes: BaseNote[]; context: h.JSX.Element | undefined }
|
||||||
|
> {
|
||||||
rawNotes: BaseNote[];
|
rawNotes: BaseNote[];
|
||||||
|
|
||||||
private searchObservableServer = new Observable<void>(1000);
|
private searchObservableServer = new Observable<void>(1000);
|
||||||
private searchObservable = this.searchObservableServer.getPublicApi();
|
private searchObservable = this.searchObservableServer.getPublicApi();
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
console.log("Creating new Instance of EntryList")
|
console.log("Creating new Instance of EntryList");
|
||||||
this.state = { notes: [], context: undefined }
|
this.state = { notes: [], context: undefined };
|
||||||
this.onDragOver = this.onDragOver.bind(this);
|
this.onDragOver = this.onDragOver.bind(this);
|
||||||
this.onDrop = this.onDrop.bind(this);
|
this.onDrop = this.onDrop.bind(this);
|
||||||
this.reloadNotes = this.reloadNotes.bind(this);
|
this.reloadNotes = this.reloadNotes.bind(this);
|
||||||
@ -27,14 +28,13 @@ export default class EntryList extends Component<{ vault: Promise<IVault> }, { n
|
|||||||
vault: IVault;
|
vault: IVault;
|
||||||
|
|
||||||
async reloadNotes(s?: boolean) {
|
async reloadNotes(s?: boolean) {
|
||||||
if (s)
|
if (s) return;
|
||||||
return;
|
|
||||||
this.rawNotes = await this.vault.getAllNotes();
|
this.rawNotes = await this.vault.getAllNotes();
|
||||||
await this.applySearch(true);
|
await this.applySearch(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentWillMount() {
|
async componentWillMount() {
|
||||||
this.vault = await this.props.vault;
|
this.vault = this.props.vault;
|
||||||
this.reloadNotes();
|
this.reloadNotes();
|
||||||
document.body.addEventListener("dragover", this.onDragOver);
|
document.body.addEventListener("dragover", this.onDragOver);
|
||||||
document.body.addEventListener("drop", this.onDrop);
|
document.body.addEventListener("drop", this.onDrop);
|
||||||
@ -59,33 +59,81 @@ export default class EntryList extends Component<{ vault: Promise<IVault> }, { n
|
|||||||
|
|
||||||
onContext(evt: MouseEvent, note: BaseNote) {
|
onContext(evt: MouseEvent, note: BaseNote) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
evt.stopPropagation();
|
||||||
|
|
||||||
|
const close = () => {
|
||||||
|
document.documentElement.removeEventListener("click", close);
|
||||||
|
this.setState({ context: undefined });
|
||||||
|
};
|
||||||
|
document.documentElement.addEventListener("click", close);
|
||||||
|
|
||||||
const shareNote = async () => {
|
const shareNote = async () => {
|
||||||
let nav = window.navigator as any;
|
let nav = window.navigator as any;
|
||||||
if (nav.share !== undefined) {
|
if (nav.share !== undefined) {
|
||||||
let vnote = await this.vault.getNote(note._id);
|
let vnote = await this.vault.getNote(note._id);
|
||||||
nav.share({ title: vnote.preview.split("\n")[0], text: vnote.__value })
|
nav.share({
|
||||||
.then(() => console.log('Successful share'))
|
title: vnote.preview.split("\n")[0],
|
||||||
.catch(error => {
|
text: vnote.__value,
|
||||||
console.error('Error sharing:', error)
|
})
|
||||||
Notifications.sendError(error)
|
.then(() => console.log("Successful share"))
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error sharing:", error);
|
||||||
|
Notifications.sendError(error);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Notifications.sendError("Sharing not possible on this device")
|
Notifications.sendError("Sharing not possible on this device");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
const deleteNote = async () => {
|
||||||
|
this.vault
|
||||||
|
.deleteNote(note._id)
|
||||||
|
.then(() => {
|
||||||
|
Notifications.sendSuccess("Deleted");
|
||||||
|
this.rawNotes = this.rawNotes.filter((e) => e._id !== note._id);
|
||||||
|
this.setState({
|
||||||
|
notes: this.state.notes.filter((e) => e._id !== note._id),
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
Notifications.sendError(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const copyNote = async () => {
|
||||||
|
this.vault.getNote(note._id).then((note) => {
|
||||||
|
const el = document.createElement("textarea");
|
||||||
|
el.value = note.__value;
|
||||||
|
document.body.appendChild(el);
|
||||||
|
el.select();
|
||||||
|
document.execCommand("copy");
|
||||||
|
document.body.removeChild(el);
|
||||||
|
Notifications.sendSuccess("Copied");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
let share;
|
let share;
|
||||||
if ((window.navigator as any).share) {
|
if ((window.navigator as any).share) {
|
||||||
share = <button class="uk-button" onClick={() => shareNote()}>
|
share = (
|
||||||
share
|
<button class="btn" onClick={shareNote}>
|
||||||
</button>
|
share
|
||||||
let context = <ContextMenu event={evt} >
|
</button>
|
||||||
{share}
|
);
|
||||||
</ContextMenu>
|
|
||||||
|
|
||||||
this.setState({ context });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let context = (
|
||||||
|
<ContextMenu event={evt}>
|
||||||
|
{share}
|
||||||
|
<button class="btn" onClick={deleteNote}>
|
||||||
|
delete
|
||||||
|
</button>
|
||||||
|
<button class="btn" onClick={copyNote}>
|
||||||
|
copy
|
||||||
|
</button>
|
||||||
|
</ContextMenu>
|
||||||
|
);
|
||||||
|
|
||||||
|
this.setState({ context });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,57 +146,69 @@ export default class EntryList extends Component<{ vault: Promise<IVault> }, { n
|
|||||||
if (item.kind === "file") {
|
if (item.kind === "file") {
|
||||||
let file = item.getAsFile();
|
let file = item.getAsFile();
|
||||||
if (file.type !== "application/json") {
|
if (file.type !== "application/json") {
|
||||||
Notifications.sendError("Invalid File Type!!!")
|
Notifications.sendError("Invalid File Type!!!");
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
let data = await new Promise<string>((yes, no) => {
|
let data = await new Promise<string>((yes, no) => {
|
||||||
let fr = new FileReader()
|
let fr = new FileReader();
|
||||||
fr.onload = (ev) => {
|
fr.onload = (ev) => {
|
||||||
yes((ev.target as any).result);
|
yes((ev.target as any).result);
|
||||||
}
|
};
|
||||||
fr.onerror = no;
|
fr.onerror = no;
|
||||||
fr.readAsText(file);
|
fr.readAsText(file);
|
||||||
})
|
});
|
||||||
let parsed = JSON.parse(data);
|
let parsed = JSON.parse(data);
|
||||||
let c = new Error("Could not parse!");
|
let c = new Error("Could not parse!");
|
||||||
let notes: { content: string, time: Date }[] = null;
|
let notes: { content: string; time: Date }[] = null;
|
||||||
if (Array.isArray(parsed)) { // Could be from SecureNotes 1
|
if (Array.isArray(parsed)) {
|
||||||
notes = parsed.map(elm => {
|
// Could be from SecureNotes 1
|
||||||
if (typeof elm.message !== "string" || typeof elm.time !== "string") {
|
notes = parsed.map((elm) => {
|
||||||
|
if (
|
||||||
|
typeof elm.message !== "string" ||
|
||||||
|
typeof elm.time !== "string"
|
||||||
|
) {
|
||||||
throw c;
|
throw c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content: elm.message,
|
content: elm.message,
|
||||||
time: new Date(elm.time)
|
time: new Date(elm.time),
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
} else if (parsed.version) { // Could be from SecureNotes 2
|
} else if (parsed.version) {
|
||||||
if (parsed.version === 1) { //Could be from SecureNotes 2 version 1
|
// Could be from SecureNotes 2
|
||||||
notes = (parsed.notes as any[]).map(elm => {
|
if (parsed.version === 1) {
|
||||||
if (typeof elm.content !== "string" || typeof elm.time !== "string") {
|
//Could be from SecureNotes 2 version 1
|
||||||
|
notes = (parsed.notes as any[]).map((elm) => {
|
||||||
|
if (
|
||||||
|
typeof elm.content !== "string" ||
|
||||||
|
typeof elm.time !== "string"
|
||||||
|
) {
|
||||||
throw c;
|
throw c;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
content: elm.content,
|
content: elm.content,
|
||||||
time: new Date(elm.time)
|
time: new Date(elm.time),
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
throw c;
|
throw c;
|
||||||
}
|
}
|
||||||
} else
|
} else throw c;
|
||||||
throw c;
|
|
||||||
|
|
||||||
await Promise.all(notes.map(n => {
|
await Promise.all(
|
||||||
let note = this.vault.newNote();
|
notes.map((n) => {
|
||||||
note.__value = n.content;
|
let note = this.vault.newNote();
|
||||||
return this.vault.saveNote(note, n.time);
|
note.__value = n.content;
|
||||||
}));
|
return this.vault.saveNote(note, n.time);
|
||||||
|
})
|
||||||
|
);
|
||||||
await this.reloadNotes();
|
await this.reloadNotes();
|
||||||
Notifications.sendSuccess(`Imported ${notes.length} notes!`);
|
Notifications.sendSuccess(
|
||||||
|
`Imported ${notes.length} notes!`
|
||||||
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Notifications.sendError("Cannot read File!")
|
Notifications.sendError("Cannot read File!");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,8 +225,7 @@ export default class EntryList extends Component<{ vault: Promise<IVault> }, { n
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.searchLock.locked)
|
if (this.searchLock.locked) return;
|
||||||
return;
|
|
||||||
const lock = await this.searchLock.getLock();
|
const lock = await this.searchLock.getLock();
|
||||||
console.time("SearchOP");
|
console.time("SearchOP");
|
||||||
|
|
||||||
@ -180,7 +239,7 @@ export default class EntryList extends Component<{ vault: Promise<IVault> }, { n
|
|||||||
return parts.every(function (el) {
|
return parts.every(function (el) {
|
||||||
return note.preview.toLowerCase().indexOf(el) > -1;
|
return note.preview.toLowerCase().indexOf(el) > -1;
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
let elements: BaseNote[];
|
let elements: BaseNote[];
|
||||||
if (!force && this.oldSearch && search.startsWith(this.oldSearch)) {
|
if (!force && this.oldSearch && search.startsWith(this.oldSearch)) {
|
||||||
@ -189,29 +248,32 @@ export default class EntryList extends Component<{ vault: Promise<IVault> }, { n
|
|||||||
elements = [...this.rawNotes];
|
elements = [...this.rawNotes];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await new Promise((yes) => {
|
||||||
await new Promise(yes => {
|
|
||||||
const idle = () => {
|
const idle = () => {
|
||||||
window.requestIdleCallback(deadline => {
|
window.requestIdleCallback(
|
||||||
let invTR = deadline.timeRemaining() <= 0;
|
(deadline) => {
|
||||||
while ((deadline.timeRemaining() > 0 || invTR) && elements.length > 0) {
|
let invTR = deadline.timeRemaining() <= 0;
|
||||||
let element = elements.shift();
|
while (
|
||||||
if (match(element)) {
|
(deadline.timeRemaining() > 0 || invTR) &&
|
||||||
notes.push(element);
|
elements.length > 0
|
||||||
|
) {
|
||||||
|
let element = elements.shift();
|
||||||
|
if (match(element)) {
|
||||||
|
notes.push(element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (elements.length > 0) idle();
|
||||||
if (elements.length > 0)
|
else yes();
|
||||||
idle();
|
},
|
||||||
else
|
{ timeout: 100 }
|
||||||
yes();
|
);
|
||||||
}, { timeout: 100 });
|
};
|
||||||
}
|
|
||||||
idle();
|
idle();
|
||||||
})
|
});
|
||||||
// notes = elements.filter(note => match(note));
|
// notes = elements.filter(note => match(note));
|
||||||
}
|
}
|
||||||
|
|
||||||
await new Promise(yes => this.setState({ notes }, yes));
|
await new Promise((yes) => this.setState({ notes }, yes));
|
||||||
this.oldSearch = search;
|
this.oldSearch = search;
|
||||||
lock.release();
|
lock.release();
|
||||||
console.timeEnd("SearchOP");
|
console.timeEnd("SearchOP");
|
||||||
@ -227,40 +289,63 @@ export default class EntryList extends Component<{ vault: Promise<IVault> }, { n
|
|||||||
searchInput: HTMLInputElement;
|
searchInput: HTMLInputElement;
|
||||||
render() {
|
render() {
|
||||||
const open_entry = (id: string | null) => {
|
const open_entry = (id: string | null) => {
|
||||||
Navigation.setPage("/vault", { id: this.vault.id }, { id, entry: "true" })
|
Navigation.setPage(
|
||||||
}
|
"/vault",
|
||||||
|
{ id: this.vault.id },
|
||||||
|
{ id, entry: "true" }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return <div>
|
return (
|
||||||
{this.state.context}
|
<div>
|
||||||
<header class="uk-background-primary">
|
{this.state.context}
|
||||||
<a class="header-icon-button" onClick={() => history.back()}><ArrowLeft height={undefined} width={undefined} /></a>
|
<header class="header">
|
||||||
<h3 style="display:inline" class="header-title" onClick={() => Navigation.setPage("/")}>{this.vault ? this.vault.name : ""}</h3>
|
<div class="header-icon-button" onClick={() => history.back()}>
|
||||||
<span></span>
|
<ArrowLeft height={undefined} width={undefined} />
|
||||||
{/* <a class="button header_icon_button"><MoreVertival height={undefined} width={undefined} /></a> */}
|
</div>
|
||||||
</header>
|
<span onClick={() => Navigation.setPage("/")}>
|
||||||
<AddButton onClick={() => open_entry(null)} />
|
{this.vault ? this.vault.name : ""}
|
||||||
<div class="uk-container">
|
</span>
|
||||||
<div style="display:flex;">
|
<span></span>
|
||||||
<input class="uk-input" type="text" onKeyUp={this.searchChanged} ref={elm => this.searchInput = elm} />
|
{/* <a class="button header_icon_button"><MoreVertival height={undefined} width={undefined} /></a> */}
|
||||||
<button class="uk-button" style="padding: 0 10px;">
|
</header>
|
||||||
<Search />
|
<AddButton onClick={() => open_entry(null)} />
|
||||||
</button>
|
<div class="container">
|
||||||
</div>
|
<div style="display:flex; margin-top: .5rem;">
|
||||||
|
<input
|
||||||
|
class="inp"
|
||||||
|
type="text"
|
||||||
|
style="width: 100%; height: 40px;"
|
||||||
|
onKeyUp={this.searchChanged}
|
||||||
|
ref={(elm) => (this.searchInput = elm)}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
class="btn btn-primary"
|
||||||
|
style="padding: 5px 10px; margin: 0; height: 40px; width: 40px;"
|
||||||
|
>
|
||||||
|
<Search />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="uk-child-width-1-3@m uk-grid-small uk-grid-match" style="margin-top: 1rem;" uk-grid>
|
<div class="vault-list" style="margin-top: 1rem;">
|
||||||
{this.state.notes.map(note => {
|
{this.state.notes.map((note) => {
|
||||||
let [first, second] = note.preview.split("\n", 2);
|
let [first, second] = note.preview.split("\n", 2);
|
||||||
return <div class="" onContextMenu={evt => this.onContext(evt, note)} onClick={() => {
|
return (
|
||||||
open_entry(note._id)
|
<div
|
||||||
}}>
|
class="card vault-vault"
|
||||||
<div class="uk-card uk-card-default uk-card-body vault-vault" style="box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3)">
|
onContextMenu={(evt) => this.onContext(evt, note)}
|
||||||
<div>{first}</div>
|
onClick={() => {
|
||||||
<div>{second}</div>
|
open_entry(note._id);
|
||||||
</div>
|
}}
|
||||||
</div>
|
>
|
||||||
})}
|
<div>{first}</div>
|
||||||
|
<div>{second}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,47 +1,55 @@
|
|||||||
import { h } from "preact"
|
import { h } from "preact";
|
||||||
import { Page } from "../../../page";
|
import { Page } from "../../../page";
|
||||||
import Notes, { IVault, BaseNote } from "../../../notes";
|
import Notes, { IVault, BaseNote } from "../../../notes";
|
||||||
import Navigation from "../../../navigation";
|
import Navigation from "../../../navigation";
|
||||||
import EntryComponent from "./Entry";
|
import EntryComponent from "./Entry";
|
||||||
import EntryList from "./EntryList";
|
import EntryList from "./EntryList";
|
||||||
|
|
||||||
import "./vault.scss"
|
import "./vault.scss";
|
||||||
|
import { useState } from "preact/hooks";
|
||||||
|
import { usePromise } from "../../../hooks";
|
||||||
|
|
||||||
export interface VaultProps {
|
export interface VaultProps {
|
||||||
state: { id: string };
|
state: { id: string };
|
||||||
hidden: { entry: string, id: string, note: string };
|
hidden: { entry: string; id: string; note: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class VaultPage extends Page<VaultProps, { entries: BaseNote[] }> {
|
export default function VaultPage(props: VaultProps) {
|
||||||
vault: Promise<IVault>
|
console.log("Vault page");
|
||||||
constructor(props: VaultProps) {
|
const [loading, error, vault] = usePromise(
|
||||||
super(props);
|
() =>
|
||||||
this.state = { entries: [] };
|
Notes.getVault(
|
||||||
}
|
this.props.state.id,
|
||||||
|
Notes.getVaultKey(this.props.state.id)
|
||||||
|
),
|
||||||
|
[props.state.id]
|
||||||
|
);
|
||||||
|
|
||||||
async componentWillMount() {
|
if (vault) {
|
||||||
this.vault = Notes.getVault(this.props.state.id, Notes.getVaultKey(this.props.state.id))
|
window.debug.activeVault = vault;
|
||||||
this.vault.then(vlt => {
|
window.debug.createNotes = (cnt = 10) => {
|
||||||
window.debug.activeVault = vlt;
|
for (let i = 0; i < cnt; i++) {
|
||||||
window.debug.createNotes = (cnt = 10) => {
|
let nt = vault.newNote();
|
||||||
for (let i = 0; i < cnt; i++) {
|
nt.__value = `Random Note ${i}\ With some Content ${i}`;
|
||||||
let nt = vlt.newNote();
|
vault.saveNote(nt);
|
||||||
nt.__value = `Random Note ${i}\ With some Content ${i}`;
|
|
||||||
vlt.saveNote(nt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
};
|
||||||
this.vault.catch(err => {
|
|
||||||
Navigation.setPage("/")
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
if (loading) return <div>Loading Vault</div>;
|
||||||
if (this.props.hidden && this.props.hidden.entry === "true") {
|
// Maybe return loading animation or so
|
||||||
return <EntryComponent vault={this.vault} id={this.props.hidden.id} note={this.props.hidden.note} />
|
else if (error) return <div>{error.message}</div>;
|
||||||
|
else {
|
||||||
|
if (props.hidden?.entry) {
|
||||||
|
return (
|
||||||
|
<EntryComponent
|
||||||
|
vault={vault}
|
||||||
|
id={props.hidden.id}
|
||||||
|
note={props.hidden.note}
|
||||||
|
/>
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return <EntryList vault={this.vault} />
|
return <EntryList vault={vault} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,28 @@
|
|||||||
|
.container> :last-child {
|
||||||
|
margin-bottom: 15px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.vault-list {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
grid-gap: 1rem;
|
||||||
|
grid-auto-rows: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 50rem) {
|
||||||
|
.vault-list {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Media Query for small screens
|
||||||
|
|
||||||
.vault-vault {
|
.vault-vault {
|
||||||
width: 100%;
|
overflow: hidden;
|
||||||
|
|
||||||
>div {
|
>div {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 1rem;
|
font-size: 1.1rem;
|
||||||
margin-left: 1rem;
|
margin-left: 1rem;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
@ -17,27 +35,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
>div:empty {
|
>div:empty {
|
||||||
&::before{
|
&::before {
|
||||||
content: " ";
|
content: " ";
|
||||||
white-space: pre;
|
white-space: pre;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// .vault_vault {
|
|
||||||
// padding: 0.5rem;
|
|
||||||
// border-bottom: solid 1px var(--card-border-color);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// .vault_vault:hover {
|
|
||||||
// background: var(--nav-hover-back-color);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// .vault_vault>svg {
|
|
||||||
// height: 2rem;
|
|
||||||
// margin-right: 1rem;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// .vault_vault:last-child {
|
|
||||||
// border-bottom: none;
|
|
||||||
// }
|
|
@ -1,9 +1,8 @@
|
|||||||
import { h } from "preact"
|
import { h } from "preact";
|
||||||
import { Page } from "../../../page";
|
import { Page } from "../../../page";
|
||||||
import Notes, { VaultList } from "../../../notes";
|
import Notes, { VaultList } from "../../../notes";
|
||||||
import "./vaults.scss"
|
import "./vaults.scss";
|
||||||
import Lock from "feather-icons/dist/icons/lock.svg";
|
import { Lock, Unlock, Settings } from "preact-feather";
|
||||||
import Unlock from "feather-icons/dist/icons/unlock.svg";
|
|
||||||
import Navigation from "../../../navigation";
|
import Navigation from "../../../navigation";
|
||||||
import { InputModal } from "../../modals/InputModal";
|
import { InputModal } from "../../modals/InputModal";
|
||||||
import { YesNoModal } from "../../modals/YesNoModal";
|
import { YesNoModal } from "../../modals/YesNoModal";
|
||||||
@ -17,7 +16,14 @@ export interface VaultsProps {
|
|||||||
onSelected?: (vaultid: string) => void;
|
onSelected?: (vaultid: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class VaultsPage extends Page<VaultsProps, { vaults: VaultList, modal: JSX.Element | undefined, context: JSX.Element | undefined }> {
|
export default class VaultsPage extends Page<
|
||||||
|
VaultsProps,
|
||||||
|
{
|
||||||
|
vaults: VaultList;
|
||||||
|
modal: h.JSX.Element | undefined;
|
||||||
|
context: h.JSX.Element | undefined;
|
||||||
|
}
|
||||||
|
> {
|
||||||
constructor(props: VaultsProps) {
|
constructor(props: VaultsProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = { vaults: [], modal: undefined, context: undefined };
|
this.state = { vaults: [], modal: undefined, context: undefined };
|
||||||
@ -25,15 +31,14 @@ export default class VaultsPage extends Page<VaultsProps, { vaults: VaultList, m
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateVaults(s?: boolean) {
|
updateVaults(s?: boolean) {
|
||||||
if (s)
|
if (s) return;
|
||||||
return;
|
return new Promise<void>((yes) => {
|
||||||
return new Promise(yes => {
|
Notes.getVaults().then((vaults) => this.setState({ vaults }, yes));
|
||||||
Notes.getVaults().then(vaults => this.setState({ vaults }, yes))
|
});
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this.updateVaults()
|
this.updateVaults();
|
||||||
Notes.syncObservable.subscribe(this.updateVaults);
|
Notes.syncObservable.subscribe(this.updateVaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,15 +46,19 @@ export default class VaultsPage extends Page<VaultsProps, { vaults: VaultList, m
|
|||||||
Notes.syncObservable.unsubscribe(this.updateVaults);
|
Notes.syncObservable.unsubscribe(this.updateVaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getKey(vault: { name: string, id: string }, permanent = true) {
|
async getKey(vault: { name: string; id: string }, permanent = true) {
|
||||||
let inp_mod = new InputModal("Enter password for " + vault.name, "Password", "password");
|
let inp_mod = new InputModal(
|
||||||
|
"Enter password for " + vault.name,
|
||||||
|
"Password",
|
||||||
|
"password"
|
||||||
|
);
|
||||||
let key = undefined;
|
let key = undefined;
|
||||||
while (true) {
|
while (true) {
|
||||||
// inp_mod.show();
|
// inp_mod.show();
|
||||||
let value = await inp_mod.getResult(false);
|
let value = await inp_mod.getResult(false);
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
console.log("Value is null")
|
console.log("Value is null");
|
||||||
inp_mod.close()
|
inp_mod.close();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
key = Notes.passwordToKey(value);
|
key = Notes.passwordToKey(value);
|
||||||
@ -57,11 +66,11 @@ export default class VaultsPage extends Page<VaultsProps, { vaults: VaultList, m
|
|||||||
await Notes.getVault(vault.id, key);
|
await Notes.getVault(vault.id, key);
|
||||||
break;
|
break;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Notifications.sendError("Invalid password!")
|
Notifications.sendError("Invalid password!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inp_mod.close()
|
inp_mod.close();
|
||||||
|
|
||||||
let perm = false;
|
let perm = false;
|
||||||
if (permanent) {
|
if (permanent) {
|
||||||
@ -78,27 +87,24 @@ export default class VaultsPage extends Page<VaultsProps, { vaults: VaultList, m
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async openVault(vault: { name: string, encrypted: boolean, id: string }) {
|
async openVault(vault: { name: string; encrypted: boolean; id: string }) {
|
||||||
const action = () => {
|
const action = () => {
|
||||||
if (this.props.selectVault) {
|
if (this.props.selectVault) {
|
||||||
this.props.onSelected(vault.id);
|
this.props.onSelected(vault.id);
|
||||||
} else {
|
} else {
|
||||||
Navigation.setPage("/vault", { id: vault.id })
|
Navigation.setPage("/vault", { id: vault.id });
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
if (vault.encrypted) {
|
if (vault.encrypted) {
|
||||||
let key = Notes.getVaultKey(vault.id);
|
let key = Notes.getVaultKey(vault.id);
|
||||||
if (key)
|
if (key) action();
|
||||||
action()
|
|
||||||
else {
|
else {
|
||||||
if (await this.getKey(vault))
|
if (await this.getKey(vault)) action();
|
||||||
action();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
action()
|
action();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async addButtonClick() {
|
async addButtonClick() {
|
||||||
@ -112,121 +118,177 @@ export default class VaultsPage extends Page<VaultsProps, { vaults: VaultList, m
|
|||||||
|
|
||||||
let password;
|
let password;
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
let password_modal = new InputModal("Enter new password", "Password", "password");
|
let password_modal = new InputModal(
|
||||||
|
"Enter new password",
|
||||||
|
"Password",
|
||||||
|
"password"
|
||||||
|
);
|
||||||
password = await password_modal.getResult();
|
password = await password_modal.getResult();
|
||||||
if (password === null) return;
|
if (password === null) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let key;
|
let key;
|
||||||
if (password) {
|
if (password) {
|
||||||
key = Notes.passwordToKey(password)
|
key = Notes.passwordToKey(password);
|
||||||
}
|
}
|
||||||
await Notes.createVault(name, key)
|
await Notes.createVault(name, key);
|
||||||
this.updateVaults();
|
this.updateVaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
onContext(evt: MouseEvent, vault: { name: string, encrypted: boolean, id: string }) {
|
onContext(
|
||||||
|
evt: MouseEvent,
|
||||||
|
vault: { name: string; encrypted: boolean; id: string }
|
||||||
|
) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
evt.stopPropagation();
|
||||||
|
|
||||||
const close = () => {
|
const close = () => {
|
||||||
window.removeEventListener("click", close);
|
document.documentElement.removeEventListener("click", close);
|
||||||
this.setState({ context: undefined });
|
this.setState({ context: undefined });
|
||||||
}
|
};
|
||||||
window.addEventListener("click", close);
|
document.documentElement.addEventListener("click", close);
|
||||||
|
|
||||||
let deleteb = <button class="uk-button" onClick={async () => {
|
let deleteb = (
|
||||||
let delete_modal = new YesNoModal("Delete Vault? Cannot be undone!");
|
<button
|
||||||
let result = await delete_modal.getResult();
|
class="btn"
|
||||||
if (result) {
|
onClick={async () => {
|
||||||
Notes.deleteVault(vault.id).then(() => {
|
let delete_modal = new YesNoModal(
|
||||||
this.updateVaults();
|
"Delete Vault? Cannot be undone!"
|
||||||
}).catch(err => {
|
);
|
||||||
Notifications.sendError("error deleting vault!")
|
let result = await delete_modal.getResult();
|
||||||
console.error(err);
|
if (result) {
|
||||||
})
|
Notes.deleteVault(vault.id)
|
||||||
}
|
.then(() => {
|
||||||
}}>
|
this.updateVaults();
|
||||||
delete
|
})
|
||||||
</button>;
|
.catch((err) => {
|
||||||
|
Notifications.sendError("Error deleting vault!");
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
delete
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
|
||||||
let delete_key;
|
let delete_key;
|
||||||
if (Notes.getVaultKey(vault.id)) {
|
if (Notes.getVaultKey(vault.id)) {
|
||||||
delete_key = <button class="uk-button" onClick={() => {
|
delete_key = (
|
||||||
Notes.forgetVaultKey(vault.id);
|
<button
|
||||||
Notifications.sendSuccess("Forgot key!")
|
class="btn"
|
||||||
}}>
|
onClick={() => {
|
||||||
forget password
|
Notes.forgetVaultKey(vault.id);
|
||||||
</button>;
|
Notifications.sendSuccess("Forgot password!");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
forget password
|
||||||
|
</button>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let exportb = <button class="uk-button" onClick={async () => {
|
let exportb = (
|
||||||
let key: Uint8Array;
|
<button
|
||||||
if (vault.encrypted) {
|
class="btn"
|
||||||
await this.getKey(vault, false)
|
onClick={async () => {
|
||||||
key = Notes.getVaultKey(vault.id);
|
let key: Uint8Array;
|
||||||
}
|
if (vault.encrypted) {
|
||||||
let note_vault = await Notes.getVault(vault.id, key);
|
await this.getKey(vault, false);
|
||||||
let base_notes = await note_vault.getAllNotes();
|
key = Notes.getVaultKey(vault.id);
|
||||||
let notes = await Promise.all(base_notes.map(e => {
|
|
||||||
return note_vault.getNote(e._id);
|
|
||||||
}));
|
|
||||||
|
|
||||||
let result =
|
|
||||||
{
|
|
||||||
version: 1,
|
|
||||||
notes: notes.map(e => {
|
|
||||||
return {
|
|
||||||
content: e.__value,
|
|
||||||
time: e.time
|
|
||||||
}
|
}
|
||||||
})
|
let note_vault = await Notes.getVault(vault.id, key);
|
||||||
}
|
let base_notes = await note_vault.getAllNotes();
|
||||||
|
let notes = await Promise.all(
|
||||||
|
base_notes.map((e) => {
|
||||||
|
return note_vault.getNote(e._id);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(result, undefined, 3));
|
let result = {
|
||||||
var downloadAnchorNode = document.createElement('a');
|
version: 1,
|
||||||
downloadAnchorNode.setAttribute("href", dataStr);
|
notes: notes.map((e) => {
|
||||||
downloadAnchorNode.setAttribute("download", "notes_export_" + vault.name + ".json");
|
return {
|
||||||
document.body.appendChild(downloadAnchorNode); // required for firefox
|
content: e.__value,
|
||||||
downloadAnchorNode.click();
|
time: e.time,
|
||||||
downloadAnchorNode.remove();
|
};
|
||||||
}}>
|
}),
|
||||||
export
|
};
|
||||||
</button>;
|
|
||||||
|
|
||||||
let context = <ContextMenu event={evt} >
|
var dataStr =
|
||||||
{deleteb}
|
"data:text/json;charset=utf-8," +
|
||||||
{delete_key}
|
encodeURIComponent(JSON.stringify(result, undefined, 3));
|
||||||
{exportb}
|
var downloadAnchorNode = document.createElement("a");
|
||||||
</ContextMenu>
|
downloadAnchorNode.setAttribute("href", dataStr);
|
||||||
|
downloadAnchorNode.setAttribute(
|
||||||
|
"download",
|
||||||
|
"notes_export_" + vault.name + ".json"
|
||||||
|
);
|
||||||
|
document.body.appendChild(downloadAnchorNode); // required for firefox
|
||||||
|
downloadAnchorNode.click();
|
||||||
|
downloadAnchorNode.remove();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
export
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
|
||||||
|
let context = (
|
||||||
|
<ContextMenu event={evt}>
|
||||||
|
{deleteb}
|
||||||
|
{delete_key}
|
||||||
|
{exportb}
|
||||||
|
</ContextMenu>
|
||||||
|
);
|
||||||
|
|
||||||
this.setState({ context });
|
this.setState({ context });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let elms = this.state.vaults.map(vault => {
|
console.log({ vaults: this.state.vaults })
|
||||||
return <li class="vaults_vault" onClick={() => this.openVault(vault)} onContextMenu={(evt) => this.onContext(evt, vault)}>
|
let elms = this.state.vaults.map((vault) => {
|
||||||
{vault.encrypted ? <Lock height={undefined} width={undefined} /> : <Unlock height={undefined} width={undefined} />}
|
return (
|
||||||
<span>
|
<li
|
||||||
{vault.name}
|
class="vaults_vault"
|
||||||
</span>
|
onClick={() => this.openVault(vault)}
|
||||||
</li>
|
onContextMenu={(evt) => this.onContext(evt, vault)}
|
||||||
})
|
>
|
||||||
|
{vault.encrypted ? (
|
||||||
|
<Lock height={undefined} width={undefined} />
|
||||||
|
) : (
|
||||||
|
<Unlock height={undefined} width={undefined} />
|
||||||
|
)}
|
||||||
|
<span>{vault.name}</span>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return <div style={{ marginTop: "-12px", paddingTop: "12px" }} >
|
return (
|
||||||
{/* {this.state.modal} */}
|
<div style={{ marginTop: "-12px", paddingTop: "12px" }}>
|
||||||
{this.state.context}
|
{/* {this.state.modal} */}
|
||||||
<header class="uk-background-primary">
|
{this.state.context}
|
||||||
<span></span>
|
<header class="header">
|
||||||
<h3 style="display:inline" class="header_title" onClick={() => Navigation.setPage("/")}>Your vaults:</h3>
|
<span></span>
|
||||||
<span></span>
|
<span
|
||||||
</header>
|
style="display:inline"
|
||||||
<AddButton onClick={() => this.addButtonClick()} />
|
onClick={() => Navigation.setPage("/")}
|
||||||
<div class="uk-container">
|
>
|
||||||
<ul class="uk-list uk-list-divider">
|
{this.props.selectVault
|
||||||
{elms}
|
? "Select Vault for share"
|
||||||
</ul>
|
: "Your vaults:"}
|
||||||
|
</span>
|
||||||
|
<div
|
||||||
|
class="header-icon-button"
|
||||||
|
onClick={() => Navigation.setPage("/settings")}
|
||||||
|
>
|
||||||
|
<Settings height={undefined} width={undefined} />
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<AddButton onClick={() => this.addButtonClick()} />
|
||||||
|
<div class="container">
|
||||||
|
<ul class="list list-divider list-clickable">{elms}</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,19 @@
|
|||||||
@import "../../../vars.scss";
|
|
||||||
|
|
||||||
.vaults_vault {
|
.vaults_vault {
|
||||||
|
display: flex;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
margin-top: 0 !important;
|
margin-top: 0 !important;
|
||||||
|
align-items: flex-end;
|
||||||
|
justify-content: start;
|
||||||
|
|
||||||
// >span {
|
>span {
|
||||||
// font-size: 2rem !important;
|
font-size: 1.5rem;
|
||||||
// }
|
line-height: 1.5rem;
|
||||||
|
}
|
||||||
// &:not(:last-child) {
|
|
||||||
// border-bottom: 1px $border_color solid;
|
|
||||||
// }
|
|
||||||
|
|
||||||
>svg {
|
>svg {
|
||||||
height: 2rem;
|
display: inline-block;
|
||||||
|
height: 1.5em;
|
||||||
|
width: 1.5em;
|
||||||
margin-right: 1rem;
|
margin-right: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background: $hover-background;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -5,7 +5,6 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
padding-bottom: 40px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.transition_slidein {
|
.transition_slidein {
|
||||||
@ -21,6 +20,7 @@
|
|||||||
from {
|
from {
|
||||||
left: 100%;
|
left: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
to {
|
to {
|
||||||
left: 0%;
|
left: 0%;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
import { Lock } from "@hibas123/utils";
|
import { Lock } from "@hibas123/utils";
|
||||||
|
|
||||||
import { DB, openDb, Transaction } from "idb";
|
import { openDB, IDBPDatabase, IDBPTransaction, } from "idb";
|
||||||
|
|
||||||
export default class IDB {
|
export default class IDB {
|
||||||
initLock = new Lock();
|
initLock = new Lock();
|
||||||
db: DB;
|
db: IDBPDatabase;
|
||||||
constructor(database: string, private stores: string[]) {
|
constructor(database: string, private stores: string[]) {
|
||||||
let lock = this.initLock.getLock();
|
this.initLock.getLock().then(async l => {
|
||||||
lock.then(async l => {
|
|
||||||
|
|
||||||
let v = localStorage.getItem(database + "_version");
|
let v = localStorage.getItem(database + "_version");
|
||||||
let version = 0;
|
let version = 0;
|
||||||
if (v) version = Number(v)
|
if (v) version = Number(v)
|
||||||
@ -21,12 +19,15 @@ export default class IDB {
|
|||||||
localStorage.setItem(database + "_version", version.toString());
|
localStorage.setItem(database + "_version", version.toString());
|
||||||
localStorage.setItem(database + "_stores", stores.join(","));
|
localStorage.setItem(database + "_stores", stores.join(","));
|
||||||
|
|
||||||
this.db = await openDb(database, version, db => {
|
this.db = await openDB(database, version, {
|
||||||
console.log("IndexedDB need update")
|
upgrade: (db) => {
|
||||||
stores.forEach(store => {
|
console.log("IndexedDB need update")
|
||||||
if (!db.objectStoreNames.contains(store))
|
const check = name => (<any>db.objectStoreNames as DOMStringList).contains ? (<any>db.objectStoreNames as DOMStringList).contains(name) : db.objectStoreNames.find(e => e === name);
|
||||||
db.createObjectStore(store);
|
stores.forEach(store => {
|
||||||
})
|
if (!check(store))
|
||||||
|
db.createObjectStore(store);
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
console.log("Got DATABASE", this.db)
|
console.log("Got DATABASE", this.db)
|
||||||
l.release();
|
l.release();
|
||||||
@ -48,42 +49,42 @@ export default class IDB {
|
|||||||
return {
|
return {
|
||||||
name: name,
|
name: name,
|
||||||
transaction: () => {
|
transaction: () => {
|
||||||
return this.db.transaction(name, "readwrite")
|
return <any>this.db.transaction(name, "readwrite") as IDBPTransaction<unknown, string[]>;
|
||||||
},
|
},
|
||||||
get: async (key: string, transaction?: Transaction): Promise<T> => {
|
get: async (key: string, transaction?: IDBPTransaction<unknown, string[]>): Promise<T> => {
|
||||||
(await this.initLock.getLock()).release()
|
(await this.initLock.getLock()).release()
|
||||||
return (transaction || this.db.transaction(name))
|
return (transaction || this.db.transaction(name))
|
||||||
.objectStore(name).get(key);
|
.objectStore(name).get(key);
|
||||||
},
|
},
|
||||||
|
|
||||||
getAll: async (transaction?: Transaction): Promise<T[]> => {
|
getAll: async (transaction?: IDBPTransaction<unknown, string[]>): Promise<T[]> => {
|
||||||
(await this.initLock.getLock()).release()
|
(await this.initLock.getLock()).release()
|
||||||
return (transaction || this.db.transaction(name))
|
return (transaction || this.db.transaction(name))
|
||||||
.objectStore(name).getAll();
|
.objectStore(name).getAll();
|
||||||
},
|
},
|
||||||
|
|
||||||
set: async (key: string, val: T, transaction?: Transaction) => {
|
set: async (key: string, val: T, transaction?: IDBPTransaction<unknown, string[]>) => {
|
||||||
(await this.initLock.getLock()).release()
|
(await this.initLock.getLock()).release()
|
||||||
const tx = (transaction || this.db.transaction(name, "readwrite"));
|
const tx = (transaction || this.db.transaction(name, "readwrite"));
|
||||||
tx.objectStore(name).put(val, key);
|
tx.objectStore(name).put(val, key);
|
||||||
return tx.complete;
|
return tx.done;
|
||||||
},
|
},
|
||||||
|
|
||||||
delete: async (key: string, transaction?: Transaction) => {
|
delete: async (key: string, transaction?: IDBPTransaction<unknown, string[]>) => {
|
||||||
(await this.initLock.getLock()).release()
|
(await this.initLock.getLock()).release()
|
||||||
const tx = (transaction || this.db.transaction(name, "readwrite"));
|
const tx = (transaction || this.db.transaction(name, "readwrite"));
|
||||||
tx.objectStore(name).delete(key);
|
tx.objectStore(name).delete(key);
|
||||||
return tx.complete;
|
return tx.done;
|
||||||
},
|
},
|
||||||
|
|
||||||
clear: async (transaction?: Transaction) => {
|
clear: async (transaction?: IDBPTransaction<unknown, string[]>) => {
|
||||||
(await this.initLock.getLock()).release()
|
(await this.initLock.getLock()).release()
|
||||||
const tx = (transaction || this.db.transaction(name, "readwrite"));
|
const tx = (transaction || this.db.transaction(name, "readwrite"));
|
||||||
tx.objectStore(name).clear();
|
tx.objectStore(name).clear();
|
||||||
return tx.complete;
|
return tx.done;
|
||||||
},
|
},
|
||||||
|
|
||||||
keys: async (transaction?: Transaction): Promise<string[]> => {
|
keys: async (transaction?: IDBPTransaction<unknown, string[]>): Promise<string[]> => {
|
||||||
(await this.initLock.getLock()).release()
|
(await this.initLock.getLock()).release()
|
||||||
const tx = (transaction || this.db.transaction(name));
|
const tx = (transaction || this.db.transaction(name));
|
||||||
const keys: string[] = [];
|
const keys: string[] = [];
|
||||||
@ -91,13 +92,15 @@ export default class IDB {
|
|||||||
|
|
||||||
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari.
|
// This would be store.getAllKeys(), but it isn't supported by Edge or Safari.
|
||||||
// openKeyCursor isn't supported by Safari, so we fall back
|
// openKeyCursor isn't supported by Safari, so we fall back
|
||||||
(store.iterateKeyCursor || store.iterateCursor).call(store, (cursor: any) => {
|
store.getAllKeys()
|
||||||
if (!cursor) return;
|
|
||||||
keys.push(cursor.key);
|
|
||||||
cursor.continue();
|
|
||||||
});
|
|
||||||
|
|
||||||
return tx.complete.then(() => keys);
|
// (store.iterateKeyCursor || store.iterateCursor).call(store, (cursor: any) => {
|
||||||
|
// if (!cursor) return;
|
||||||
|
// keys.push(cursor.key);
|
||||||
|
// cursor.continue();
|
||||||
|
// });
|
||||||
|
|
||||||
|
return tx.done.then(() => keys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
src/hooks.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { useEffect, useMemo, useState } from "preact/hooks";
|
||||||
|
|
||||||
|
export function usePromise<T>(promiseFnc: () => Promise<T>, params: any[]) {
|
||||||
|
const promise = useMemo(promiseFnc, params);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState(undefined);
|
||||||
|
const [value, setValue] = useState(undefined);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let canceled = false;
|
||||||
|
|
||||||
|
promise
|
||||||
|
.then((res) => setValue(res))
|
||||||
|
.catch((err) => setError(err))
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
canceled = true;
|
||||||
|
};
|
||||||
|
}, [promise]);
|
||||||
|
|
||||||
|
return [loading, error, value];
|
||||||
|
}
|
@ -4,57 +4,36 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>SecureNotes</title>
|
<title>SecureNotes</title>
|
||||||
<meta charset="utf8" />
|
<meta charset="utf8" />
|
||||||
<meta name="Description" content="Notes app">
|
<meta name="Description" content="Notes app" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
<link rel="manifest" href="/manifest.json">
|
<link rel="manifest" href="./manifest.webmanifest" />
|
||||||
<!-- <link rel="shortcut icon" href="/public/icon-72x72.png"> -->
|
<!-- <link rel="shortcut icon" href="/public/icon-72x72.png"> -->
|
||||||
|
|
||||||
<!-- Add to home screen for Safari on iOS -->
|
<!-- Add to home screen for Safari on iOS -->
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||||||
<meta name="apple-mobile-web-app-title" content="Secure Notes">
|
<meta name="apple-mobile-web-app-title" content="Secure Notes" />
|
||||||
|
|
||||||
|
<!-- sizes="180x180" -->
|
||||||
|
<!-- href="/public/apple-touch-icon.png" -->
|
||||||
|
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
<link rel="apple-touch-icon" sizes="256x256" href="./public/notepad256.png" />
|
||||||
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#3E9AE9">
|
<!-- <link
|
||||||
<meta name="msapplication-TileColor" content="#3E9AE9">
|
rel="mask-icon"
|
||||||
<meta name="theme-color" content="#3E9AE9">
|
href="/public/safari-pinned-tab.svg"
|
||||||
|
color="#1E88E5"
|
||||||
|
/> -->
|
||||||
|
<meta name="msapplication-TileColor" content="#1E88E5" />
|
||||||
|
<meta name="theme-color" content="#1E88E5" />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
<noscript> You have to enable JavaScript to use this site! </noscript>
|
||||||
You have to enable JavaScript to use this site!
|
|
||||||
</noscript>
|
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script>
|
<script>
|
||||||
// // Check that service workers are registered
|
window.debug = {}
|
||||||
// if ('serviceWorker' in navigator) {
|
|
||||||
// // Use the window load event to keep the page load performant
|
|
||||||
// window.addEventListener('load', () => {
|
|
||||||
// navigator.serviceWorker.register('/public/serviceworker.js');
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
if (navigator.serviceWorker.controller) {
|
|
||||||
if (localStorage.getItem("debug")) {
|
|
||||||
console.warn("Debuggung and service worker found, make shure to clear cache!");
|
|
||||||
}
|
|
||||||
console.log('active service worker found, no need to register')
|
|
||||||
} else {
|
|
||||||
if (localStorage.getItem("debug")) {
|
|
||||||
console.warn("Disabling Service Worker in debug mode!")
|
|
||||||
} else {
|
|
||||||
// Register the ServiceWorker
|
|
||||||
navigator.serviceWorker.register('/serviceworker.js', {
|
|
||||||
scope: '/'
|
|
||||||
}).then(function (reg) {
|
|
||||||
console.log('Service worker has been registered for scope:' + reg.scope);
|
|
||||||
navigator.serviceWorker.controller.addEventListener("cleared_cache", evt => {
|
|
||||||
console.log(evt);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
<script src="index.tsx" type="module"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
57
src/index.scss
Executable file → Normal file
@ -1,70 +1,17 @@
|
|||||||
@import "./vars.scss";
|
@import "./vars.scss";
|
||||||
|
|
||||||
* {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: 'Roboto', sans-serif; // font-family: Verdana, Geneva, sans-serif;
|
overscroll-behavior-y: contain;
|
||||||
font-size: 18px;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
html {
|
|
||||||
min-height: 100%;
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
$header-margin: .5em;
|
|
||||||
$header-icon-size: calc(1.5rem * 1);
|
|
||||||
// $header-icon-size: 100%;
|
|
||||||
|
|
||||||
header {
|
header {
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
margin-bottom: $header-margin;
|
|
||||||
align-content: center;
|
|
||||||
padding: 0.75em;
|
|
||||||
border-bottom: solid var(--border-color) 1px;
|
|
||||||
background-color: var(--primary);
|
|
||||||
|
|
||||||
>* {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
>.header-title {
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
flex-grow: 1;
|
|
||||||
margin: 0 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header-icon-button {
|
|
||||||
display: block;
|
|
||||||
margin-top: auto;
|
|
||||||
margin-bottom: auto;
|
|
||||||
color: black;
|
|
||||||
min-width: $header-icon-size;
|
|
||||||
|
|
||||||
>svg {
|
|
||||||
height: $header-icon-size;
|
|
||||||
width: $header-icon-size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.def-shadow {
|
.def-shadow {
|
||||||
box-shadow: 0px 5px 8px 2px rgba(66, 66, 66, 0.53);
|
box-shadow: 0px 5px 8px 2px rgba(66, 66, 66, 0.53);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.ccontainer {
|
.ccontainer {
|
||||||
margin: 0 1rem;
|
margin: 0 1rem;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
@ -75,4 +22,4 @@ header {
|
|||||||
max-width: 50rem;
|
max-width: 50rem;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
148
src/index.tsx
@ -1,36 +1,3 @@
|
|||||||
declare global {
|
|
||||||
interface Window {
|
|
||||||
requestIdleCallback: (callback: (deadline: { didTimeout: boolean, timeRemaining: () => number }) => void, options?: { timeout: number }) => number | NodeJS.Timeout;
|
|
||||||
cancelIdleCallback: (id: number | NodeJS.Timeout) => void;
|
|
||||||
debug: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace JSX {
|
|
||||||
interface IntrinsicElements {
|
|
||||||
"wired-button": HTMLAttributes;
|
|
||||||
"wired-card": HTMLAttributes;
|
|
||||||
"wired-checkbox": HTMLAttributes;
|
|
||||||
"wired-combo": HTMLAttributes;
|
|
||||||
"wired-fab": HTMLAttributes;
|
|
||||||
"wired-icon-button": HTMLAttributes;
|
|
||||||
"wired-input": HTMLAttributes;
|
|
||||||
"wired-item": HTMLAttributes;
|
|
||||||
"wired-lib": HTMLAttributes;
|
|
||||||
"wired-listbox": HTMLAttributes;
|
|
||||||
"wired-progress": HTMLAttributes;
|
|
||||||
"wired-radio-group": HTMLAttributes;
|
|
||||||
"wired-radio": HTMLAttributes;
|
|
||||||
"wired-slider": HTMLAttributes;
|
|
||||||
"wired-spinner": HTMLAttributes;
|
|
||||||
"wired-tabs": HTMLAttributes;
|
|
||||||
"wired-textarea": HTMLAttributes;
|
|
||||||
"wired-toggle": HTMLAttributes;
|
|
||||||
"wired-tooltip": HTMLAttributes;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// declare const window: Window;
|
|
||||||
|
|
||||||
window.requestIdleCallback =
|
window.requestIdleCallback =
|
||||||
window.requestIdleCallback ||
|
window.requestIdleCallback ||
|
||||||
@ -42,7 +9,7 @@ window.requestIdleCallback =
|
|||||||
didTimeout: false,
|
didTimeout: false,
|
||||||
timeRemaining: function () {
|
timeRemaining: function () {
|
||||||
return Math.max(0, 50 - (Date.now() - start));
|
return Math.max(0, 50 - (Date.now() - start));
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}, 1);
|
}, 1);
|
||||||
};
|
};
|
||||||
@ -57,54 +24,109 @@ console.log(window.requestIdleCallback);
|
|||||||
|
|
||||||
window.debug = {};
|
window.debug = {};
|
||||||
|
|
||||||
|
import { h, render } from "preact";
|
||||||
|
import App from "./components/App";
|
||||||
|
import "@hibas123/theme/out/base.css";
|
||||||
import { h, render } from 'preact';
|
|
||||||
import App from './components/App';
|
|
||||||
|
|
||||||
|
|
||||||
import "uikit";
|
|
||||||
import "uikit/dist/css/uikit.css"
|
|
||||||
|
|
||||||
import "./index.scss";
|
import "./index.scss";
|
||||||
import Navigation from './navigation';
|
import Navigation from "./navigation";
|
||||||
import VaultsPage from './components/routes/vaults/Vaults';
|
import VaultsPage from "./components/routes/vaults/Vaults";
|
||||||
import { Page } from './page';
|
import { Page } from "./page";
|
||||||
|
|
||||||
import Notes from "./notes"
|
import Notes from "./notes";
|
||||||
import DemoPage from './components/demo';
|
import DemoPage from "./components/demo";
|
||||||
import VaultPage from './components/routes/vault/Vault';
|
import VaultPage from "./components/routes/vault/Vault";
|
||||||
import SharePage from './components/routes/share/Share';
|
import SharePage from "./components/routes/share/Share";
|
||||||
import Notifications from './notifications';
|
import Notifications from "./notifications";
|
||||||
|
import Error404Page from "./components/routes/404";
|
||||||
|
import SettingsPage from "./components/routes/settings/Settings";
|
||||||
window.debug.notes = Notes;
|
window.debug.notes = Notes;
|
||||||
|
|
||||||
|
import Theme from "./theme";
|
||||||
|
|
||||||
|
console.log("Dark mode:", Theme.active);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// Initialize notes provider
|
// Initialize notes provider
|
||||||
if (Notes.loginRequired()) {
|
if (Notes.loginRequired()) {
|
||||||
let url = new URL(location.href)
|
let url = new URL(location.href);
|
||||||
let code = url.searchParams.get("code");
|
let code = url.searchParams.get("code");
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
let err = await Notes.getToken(code)
|
let err = await Notes.getToken(code);
|
||||||
if (err) {
|
if (err) {
|
||||||
Notifications.sendError("Login failed: " + err)
|
Notifications.sendError("Login failed: " + err);
|
||||||
Notes.login()
|
return Notes.login();
|
||||||
} else {
|
} else {
|
||||||
window.history.replaceState(null, document.title, "/" + window.location.hash);
|
window.history.replaceState(
|
||||||
|
null,
|
||||||
|
document.title,
|
||||||
|
"/" + window.location.hash
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Notes.login()
|
return Notes.login();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Notes.start();
|
await Notes.start();
|
||||||
|
|
||||||
|
if (window.navigator.storage && navigator.storage.persist) {
|
||||||
|
navigator.storage
|
||||||
|
.persisted()
|
||||||
|
.then((has) => (has ? true : navigator.storage.persist()))
|
||||||
|
.then((is) => {
|
||||||
|
console.log("Persistant Storage:", is);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Navigation.default = VaultsPage as typeof Page;
|
Navigation.default = VaultsPage as typeof Page;
|
||||||
Navigation.addPage("/vault", VaultPage as typeof Page)
|
Navigation.addPage("/vault", VaultPage as any as typeof Page);
|
||||||
Navigation.addPage("/demo", DemoPage as typeof Page)
|
Navigation.addPage("/demo", DemoPage as typeof Page);
|
||||||
Navigation.addPage("/share", SharePage as typeof Page)
|
Navigation.addPage("/share", SharePage as typeof Page);
|
||||||
|
Navigation.addPage("/settings", SettingsPage as typeof Page);
|
||||||
|
Navigation.addPage("/404", Error404Page);
|
||||||
|
const trad = window.location.pathname;
|
||||||
|
if (trad && trad !== "/" && trad !== "") {
|
||||||
|
let p: any = {};
|
||||||
|
new URL(window.location.href).searchParams.forEach(
|
||||||
|
(val, key) => (p[key] = val)
|
||||||
|
);
|
||||||
|
Navigation.setPage(trad, p, undefined, true);
|
||||||
|
// window.location.href = "/#/" + trad;
|
||||||
|
}
|
||||||
Navigation.start();
|
Navigation.start();
|
||||||
|
|
||||||
render(<App />, document.body, document.getElementById('app'));
|
render(<App />, document.body, document.getElementById("app"));
|
||||||
})()
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
if (navigator.serviceWorker.controller) {
|
||||||
|
if (localStorage.getItem("debug")) {
|
||||||
|
console.warn(
|
||||||
|
"Debuggung and service worker found, make shure to clear cache!"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
console.log("active service worker found, no need to register");
|
||||||
|
} else {
|
||||||
|
if (localStorage.getItem("debug")) {
|
||||||
|
console.warn("Disabling Service Worker in debug mode!");
|
||||||
|
} else {
|
||||||
|
// Register the ServiceWorker
|
||||||
|
navigator.serviceWorker
|
||||||
|
.register(new URL("serviceworker.js", import.meta.url), {
|
||||||
|
scope: "/",
|
||||||
|
})
|
||||||
|
.then(function (reg) {
|
||||||
|
console.log(
|
||||||
|
"Service worker has been registered for scope:" +
|
||||||
|
reg.scope
|
||||||
|
);
|
||||||
|
navigator.serviceWorker.controller.addEventListener(
|
||||||
|
"cleared_cache",
|
||||||
|
(evt) => {
|
||||||
|
console.log(evt);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
56
src/manifest.webmanifest
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
{
|
||||||
|
"short_name": "Secure Notes",
|
||||||
|
"name": "Secure Notes",
|
||||||
|
"decription": "A place to store your notes securly",
|
||||||
|
"share_target": {
|
||||||
|
"action": "/share",
|
||||||
|
"method": "GET",
|
||||||
|
"enctype": "application/x-www-form-urlencoded",
|
||||||
|
"params": {
|
||||||
|
"title": "title",
|
||||||
|
"text": "text",
|
||||||
|
"url": "url"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "public/notepad16.png",
|
||||||
|
"sizes": "16x16",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "public/notepad24.png",
|
||||||
|
"sizes": "24x24",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "public/notepad32.png",
|
||||||
|
"sizes": "32x32",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "public/notepad64.png",
|
||||||
|
"sizes": "64x64",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "public/notepad128.png",
|
||||||
|
"sizes": "128x128",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "public/notepad256.png",
|
||||||
|
"sizes": "256x256",
|
||||||
|
"type": "image/png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "public/notepad512.png",
|
||||||
|
"sizes": "512x512",
|
||||||
|
"type": "image/png"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"start_url": "/",
|
||||||
|
"display": "standalone",
|
||||||
|
"theme_color": "#1E88E5",
|
||||||
|
"background_color": "#ffffff"
|
||||||
|
}
|
@ -23,9 +23,10 @@ function parseQuery(query: string) {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PageFunction = () => JSX.Element;
|
||||||
|
|
||||||
export default class Navigation {
|
export default class Navigation {
|
||||||
private static _pages: Map<string, typeof Page> = new Map();
|
private static _pages: Map<string, typeof Page | PageFunction> = new Map();
|
||||||
private static _page: { route: string, page: JSX.Element };
|
private static _page: { route: string, page: JSX.Element };
|
||||||
private static pageObservableServer = new Observable<JSX.Element>();
|
private static pageObservableServer = new Observable<JSX.Element>();
|
||||||
public static pageObservable = Navigation.pageObservableServer.getPublicApi();
|
public static pageObservable = Navigation.pageObservableServer.getPublicApi();
|
||||||
@ -34,7 +35,7 @@ export default class Navigation {
|
|||||||
|
|
||||||
private static _page_cache = new Map<string, VNode<any>>();
|
private static _page_cache = new Map<string, VNode<any>>();
|
||||||
|
|
||||||
public static addPage(route: string, comp: typeof Page) {
|
public static addPage(route: string, comp: typeof Page | PageFunction) {
|
||||||
Navigation._pages.set(route, comp);
|
Navigation._pages.set(route, comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,9 +70,9 @@ export default class Navigation {
|
|||||||
let oldkey = whash + serializQuery(history.state);
|
let oldkey = whash + serializQuery(history.state);
|
||||||
if (newkey !== oldkey) {
|
if (newkey !== oldkey) {
|
||||||
if (replace)
|
if (replace)
|
||||||
window.history.replaceState(hidden, document.title, newhash);
|
window.history.replaceState(hidden, document.title, "./" + newhash);
|
||||||
else
|
else
|
||||||
window.history.pushState(hidden, document.title, newhash);
|
window.history.pushState(hidden, document.title, "./" + newhash);
|
||||||
}
|
}
|
||||||
let page = this._page_cache.get(newkey);
|
let page = this._page_cache.get(newkey);
|
||||||
if (!page) {
|
if (!page) {
|
||||||
|
1242
src/notes.ts
3313
src/public/encoding.js
Normal file
0
public/favicon.ico → src/public/favicon.ico
Executable file → Normal file
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
0
public/notepad128.png → src/public/notepad128.png
Executable file → Normal file
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
0
public/notepad16.png → src/public/notepad16.png
Executable file → Normal file
Before Width: | Height: | Size: 562 B After Width: | Height: | Size: 562 B |
0
public/notepad24.png → src/public/notepad24.png
Executable file → Normal file
Before Width: | Height: | Size: 554 B After Width: | Height: | Size: 554 B |
0
public/notepad256.png → src/public/notepad256.png
Executable file → Normal file
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
0
public/notepad32.png → src/public/notepad32.png
Executable file → Normal file
Before Width: | Height: | Size: 720 B After Width: | Height: | Size: 720 B |
0
public/notepad512.png → src/public/notepad512.png
Executable file → Normal file
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.1 KiB |
0
public/notepad64.png → src/public/notepad64.png
Executable file → Normal file
Before Width: | Height: | Size: 915 B After Width: | Height: | Size: 915 B |
130
src/serviceworker.js
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
function log(...params) {
|
||||||
|
console.log.apply(this, [
|
||||||
|
...["%c[SW]: %c", "color: #f4b942;", "color:unset;"],
|
||||||
|
...params,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const CACHE = "offline";
|
||||||
|
|
||||||
|
let precacheFiles = ["/", "/index.html"];
|
||||||
|
|
||||||
|
//Install stage sets up the cache-array to configure pre-cache content
|
||||||
|
self.addEventListener("install", (evt) => {
|
||||||
|
log("The service worker is being installed.");
|
||||||
|
evt.waitUntil(
|
||||||
|
precache()
|
||||||
|
.then(() => {
|
||||||
|
log("Skip waiting on install");
|
||||||
|
})
|
||||||
|
.catch(log)
|
||||||
|
.then(() => self.skipWaiting())
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
//allow sw to control of current page
|
||||||
|
self.addEventListener("activate", (event) => {
|
||||||
|
log("Claiming clients for current page");
|
||||||
|
return self.clients.claim();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener("message", (event) => {
|
||||||
|
log("Clearing cache");
|
||||||
|
caches.delete(CACHE);
|
||||||
|
event.waitUntil(precache());
|
||||||
|
});
|
||||||
|
|
||||||
|
var Types;
|
||||||
|
(function (Types) {
|
||||||
|
Types[(Types["CACHE"] = 0)] = "CACHE";
|
||||||
|
Types[(Types["NOCACHE"] = 1)] = "NOCACHE";
|
||||||
|
Types[(Types["REFRESH"] = 2)] = "REFRESH";
|
||||||
|
Types[(Types["INDEX"] = 3)] = "INDEX";
|
||||||
|
})(Types || (Types = {}));
|
||||||
|
|
||||||
|
let rules = [
|
||||||
|
{
|
||||||
|
match: (url) => {
|
||||||
|
return url.indexOf("/api/") >= 0;
|
||||||
|
},
|
||||||
|
type: Types.NOCACHE,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
match: (url) => {
|
||||||
|
return url.indexOf("/share") >= 0;
|
||||||
|
},
|
||||||
|
type: Types.INDEX,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
match: () => {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
type: Types.REFRESH,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
self.addEventListener("fetch", (evt) => {
|
||||||
|
if (evt.request.method != "GET") return; // Dont care about POST requests
|
||||||
|
let rule = rules.find((rule) => rule.match(evt.request.url));
|
||||||
|
evt.respondWith(
|
||||||
|
(async () => {
|
||||||
|
log("Cache:", Types[rule.type]);
|
||||||
|
switch (rule.type) {
|
||||||
|
case Types.CACHE:
|
||||||
|
return fromCache(evt.request);
|
||||||
|
case Types.REFRESH:
|
||||||
|
return refresh(evt.request).then((r) => {
|
||||||
|
evt.waitUntil(r.refresh.catch((_) => {}));
|
||||||
|
return r.result;
|
||||||
|
});
|
||||||
|
case Types.NOCACHE:
|
||||||
|
return fetch(evt.request);
|
||||||
|
case Types.INDEX:
|
||||||
|
return refresh(new Request("/")).then((r) => {
|
||||||
|
evt.waitUntil(r.refresh.catch((_) => {}));
|
||||||
|
return r.result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function fromCache(request) {
|
||||||
|
let cache = await caches.open(CACHE);
|
||||||
|
let matching = await cache.match(request);
|
||||||
|
if (matching) return matching;
|
||||||
|
|
||||||
|
let res = await fetch(request.clone());
|
||||||
|
await cache.put(
|
||||||
|
request,
|
||||||
|
{
|
||||||
|
match: (url) => {
|
||||||
|
return url.indexOf("/version_hash") >= 0;
|
||||||
|
},
|
||||||
|
type: Types.NOCACHE,
|
||||||
|
},
|
||||||
|
res
|
||||||
|
);
|
||||||
|
return await cache.match(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refresh(request) {
|
||||||
|
let cache = await caches.open(CACHE);
|
||||||
|
let web = fetch(request.clone()).then((res) => {
|
||||||
|
return cache.put(request, res).then(() => {
|
||||||
|
return cache.match(request);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
let matching = await cache.match(request);
|
||||||
|
|
||||||
|
return {
|
||||||
|
result: matching ? matching : web,
|
||||||
|
refresh: web,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function precache() {
|
||||||
|
return caches.open(CACHE).then(function (cache) {
|
||||||
|
return cache.addAll(precacheFiles);
|
||||||
|
});
|
||||||
|
}
|
61
src/theme.ts
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import { AwaitStore, Observable } from "@hibas123/utils";
|
||||||
|
import { readFileSync } from "fs";
|
||||||
|
|
||||||
|
const light = readFileSync(
|
||||||
|
"node_modules/@hibas123/theme/out/light.css",
|
||||||
|
"utf-8"
|
||||||
|
);
|
||||||
|
const dark = readFileSync("node_modules/@hibas123/theme/out/dark.css", "utf-8");
|
||||||
|
|
||||||
|
export enum ThemeStates {
|
||||||
|
AUTO,
|
||||||
|
LIGHT,
|
||||||
|
DARK,
|
||||||
|
}
|
||||||
|
|
||||||
|
let themeConfig: ThemeStates = Number(localStorage.getItem("theme"));
|
||||||
|
if (Number.isNaN(themeConfig)) themeConfig = ThemeStates.AUTO;
|
||||||
|
|
||||||
|
let isDark = false;
|
||||||
|
let mediaIsDark = false;
|
||||||
|
|
||||||
|
if (window.matchMedia) {
|
||||||
|
const mediaq = matchMedia("(prefers-color-scheme: dark)");
|
||||||
|
mediaIsDark = mediaq.matches;
|
||||||
|
mediaq.onchange = (ev) => {
|
||||||
|
mediaIsDark = ev.matches;
|
||||||
|
apply();
|
||||||
|
};
|
||||||
|
console.log(mediaq);
|
||||||
|
}
|
||||||
|
|
||||||
|
const DarkModeStore = new AwaitStore<boolean>(isDark);
|
||||||
|
|
||||||
|
let styleElm: HTMLStyleElement;
|
||||||
|
function apply(force?: boolean) {
|
||||||
|
let shouldDark =
|
||||||
|
themeConfig === ThemeStates.AUTO
|
||||||
|
? mediaIsDark
|
||||||
|
: themeConfig === ThemeStates.DARK;
|
||||||
|
if (force || shouldDark !== isDark) {
|
||||||
|
if (styleElm) styleElm.remove();
|
||||||
|
styleElm = document.createElement("style");
|
||||||
|
document.head.appendChild(styleElm);
|
||||||
|
styleElm.innerHTML = shouldDark ? dark : light;
|
||||||
|
isDark = shouldDark;
|
||||||
|
DarkModeStore.send(isDark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apply(true);
|
||||||
|
|
||||||
|
function change(state: ThemeStates) {
|
||||||
|
themeConfig = state;
|
||||||
|
localStorage.setItem("theme", String(themeConfig));
|
||||||
|
apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
active: () => themeConfig,
|
||||||
|
change: (state: ThemeStates) => change(state),
|
||||||
|
isDark: DarkModeStore,
|
||||||
|
};
|
14
src/types.d.ts
vendored
@ -1,13 +1,3 @@
|
|||||||
declare module "*.svg" {
|
|
||||||
const SVG: (props: {
|
|
||||||
width?: number | undefined
|
|
||||||
height?: number | undefined
|
|
||||||
onClick?: (evt: MouseEvent) => void;
|
|
||||||
style?: string;
|
|
||||||
}) => JSX.Element;
|
|
||||||
export default SVG;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Window {
|
interface Window {
|
||||||
debug: any;
|
debug: any;
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,9 @@
|
|||||||
:root {
|
:root {
|
||||||
--primary: #1E88E5;
|
--primary: #1E88E5;
|
||||||
|
--on-primary: white;
|
||||||
// --mdc-theme-primary: var(--primary);
|
// --mdc-theme-primary: var(--primary);
|
||||||
// --mdc-theme-primary-bg: var(--mdc-theme--primary);
|
// --mdc-theme-primary-bg: var(--mdc-theme--primary);
|
||||||
// --mdc-theme-on-primary: white;
|
// --mdc-theme-on-primary: white;
|
||||||
--error: #ff2f00;
|
--error: #ff2f00;
|
||||||
--border-color: #ababab;
|
--border-color: #ababab;
|
||||||
--default-font-size: 1.05rem;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.uk-button-primary {
|
|
||||||
background: var(--primary) !important;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.uk-background-primary {
|
|
||||||
background: var(--primary) !important;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
$hover-background: #DDDDDD;
|
|
@ -1,23 +1,15 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "./public",
|
"outDir": "./public",
|
||||||
"target": "es6",
|
"target": "ES2022",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"removeComments": true,
|
"removeComments": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
"jsxFactory": "h",
|
"jsxFactory": "h",
|
||||||
"lib": [
|
"lib": ["es2015", "dom", "esnext"],
|
||||||
"es2015",
|
"resolveJsonModule": true
|
||||||
"dom",
|
},
|
||||||
"esnext"
|
"include": ["./src/types.d.ts", "./src/**/*.tsx", "./src/**/*.ts"]
|
||||||
],
|
}
|
||||||
"resolveJsonModule": true
|
|
||||||
},
|
|
||||||
"include": [
|
|
||||||
"./src/types.d.ts",
|
|
||||||
"./src/**/*.tsx",
|
|
||||||
"./src/**/*.ts"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
@ -1,97 +0,0 @@
|
|||||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
||||||
const WorkboxPlugin = require("workbox-webpack-plugin");
|
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
||||||
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
||||||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
||||||
const Visualizer = require('webpack-visualizer-plugin');
|
|
||||||
const path = require("path");
|
|
||||||
const fs = require("fs");
|
|
||||||
const config = require("./config.json");
|
|
||||||
const url = require("url");
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
devServer: {
|
|
||||||
host: "0.0.0.0", // Defaults to `localhost`
|
|
||||||
open: false, // Open the page in browser,
|
|
||||||
contentBase: path.join(__dirname, 'dist'),
|
|
||||||
disableHostCheck: true,
|
|
||||||
headers: {
|
|
||||||
"Access-Control-Allow-Origin": "*"
|
|
||||||
},
|
|
||||||
watchOptions: {
|
|
||||||
aggregateTimeout: 300,
|
|
||||||
poll: 500
|
|
||||||
},
|
|
||||||
public: url.parse(config.callback_url).hostname
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new CopyWebpackPlugin([{ from: "public" }]),
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
title: 'SecureNotes',
|
|
||||||
template: "./src/index.html"
|
|
||||||
}),
|
|
||||||
new MiniCssExtractPlugin({
|
|
||||||
filename: "[name].css",
|
|
||||||
chunkFilename: "[id].css"
|
|
||||||
}),
|
|
||||||
new BundleAnalyzerPlugin({
|
|
||||||
analyzerMode: "static",
|
|
||||||
openAnalyzer: false
|
|
||||||
}),
|
|
||||||
new Visualizer(),
|
|
||||||
// new WorkboxPlugin.GenerateSW({
|
|
||||||
// swDest: "sw.js",
|
|
||||||
// importWorkboxFrom: 'local',
|
|
||||||
// clientsClaim: true,
|
|
||||||
// // importsDirectory: "/dist",
|
|
||||||
// directoryIndex: 'index.html',
|
|
||||||
// ignoreURLParametersMatching: [/./],
|
|
||||||
// runtimeCaching: [{
|
|
||||||
// urlPattern: /images/,
|
|
||||||
// handler: 'CacheFirst',
|
|
||||||
// options: {
|
|
||||||
// cacheName: 'images',
|
|
||||||
// expiration: {
|
|
||||||
// maxEntries: 1000,
|
|
||||||
// //Recheck after 30 Days
|
|
||||||
// maxAgeSeconds: 30 * 24 * 60 * 60
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// }, {
|
|
||||||
// urlPattern: /api/,
|
|
||||||
// handler: 'NetworkOnly'
|
|
||||||
// }]
|
|
||||||
// })
|
|
||||||
],
|
|
||||||
entry: "./src/index.tsx",
|
|
||||||
// Enable sourcemaps for debugging webpack's output.
|
|
||||||
devtool: "eval",
|
|
||||||
resolve: {
|
|
||||||
// Add '.ts' and '.tsx' as resolvable extensions.
|
|
||||||
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.tsx?$/,
|
|
||||||
use: 'ts-loader',
|
|
||||||
exclude: /node_modules/
|
|
||||||
}, {
|
|
||||||
test: /\.(png|jpg)$/,
|
|
||||||
loader: "file-loader",
|
|
||||||
}, {
|
|
||||||
test: /\.(scss|css)$/,
|
|
||||||
use: [
|
|
||||||
"style-loader", // creates style nodes from JS strings
|
|
||||||
MiniCssExtractPlugin.loader,
|
|
||||||
"css-loader", // translates CSS into CommonJS
|
|
||||||
"sass-loader" // compiles Sass to CSS, using Node Sass by default
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.svg$/,
|
|
||||||
use: ['preact-svg-loader'],
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
};
|
|