forked from quoid/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.svelte
More file actions
119 lines (107 loc) · 3.41 KB
/
Copy pathApp.svelte
File metadata and controls
119 lines (107 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<script>
import {onMount, tick} from "svelte";
import {blur} from "svelte/transition";
import {setupMessageHandler} from "./handler.js";
import {log, notifications, settings, state} from "./store.js";
import Notification from "./Components/Shared/Notification.svelte";
import Sidebar from "./Components/Sidebar/Sidebar.svelte";
import Editor from "./Components/Editor/Editor.svelte";
import Settings from "./Components/Settings.svelte";
import logo from "./img/logo.svg";
//log messages when they come in
let logger = [];
// save errors separately so when they are cleared, they aren't removed from log
$: $log.some(a => {
if (!logger.includes(a)) {
if (a.type === "error") console[a.type](a.message);
//if ($settings.log) console[a.type](a.message);
//if (a.type === "error") errors = [a, ...errors];
logger.push(a);
}
});
// disables default cmd+s (save) and cmd+f (find) behavior
function preventKeyCommands(e) {
if (e.metaKey && (e.code === "KeyS" || e.code === "KeyF")) {
return e.preventDefault();
}
}
// app proportions can get messed up when opening/closing new tabs
async function windowResize() {
document.documentElement.style.height = "100vh";
// if tick is omitted, the style change won't apply
await tick();
document.documentElement.removeAttribute("style");
}
onMount(() => {
// environment setup
setupMessageHandler();
// start initialization process
safari.extension.dispatchMessage("REQ_INIT_DATA");
});
// currently inactive, but could be used to globally prevent auto text replacement in app
// eslint-disable-next-line no-unused-vars
function preventAutoTextReplacements(e) {
if (e.inputType === "insertReplacementText" && e.data === ". ") {
e.preventDefault();
e.target.value += " ";
}
}
</script>
<style>
.initializer {
align-items: center;
background-color: var(--color-bg-primary);
display: flex;
flex-direction: column;
height: 100%;
justify-content: center;
left: 0;
opacity: 1;
position: absolute;
top: 0;
visibility: visible;
width: 100%;
z-index: 99;
}
.initializer :global(svg) {
height: 1.5rem;
margin-bottom: 0.5rem;
}
.initializer span {
color: var(--text-color-secondary);
font: var(--text-medium);
}
div:not(.initializer) {
display: flex;
flex: 1 0 0;
overflow: hidden;
}
ul {
bottom: 1rem;
left: 50%;
position: fixed;
transform: translateX(-50%);
z-index: 98;
}
</style>
<svelte:window on:keydown={preventKeyCommands} on:resize={windowResize}/>
{#if $state.includes("init")}
<div class="initializer" out:blur="{{duration: 350}}">
{@html logo}
{#if $state.includes("init-error")}
<span>Failed to initialize app, check the console!</span>
{:else}
<span>Initializing app...</span>
{/if}
</div>
{/if}
<div>
<Sidebar/>
<Editor/>
</div>
<ul>
{#each $notifications as item (item.id)}
<Notification on:click={() => notifications.remove(item.id)} {item}/>
{/each}
</ul>
{#if $state.includes("settings")}<Settings />{/if}