sliftutils 0.39.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/storage/PrivateFileSystemStorage.ts +2 -0
- package/web/ExamplePage.tsx +48 -0
- package/web/Page.tsx +59 -0
- package/web/browser.tsx +2 -42
package/package.json
CHANGED
|
@@ -68,6 +68,7 @@ export class PrivateFileSystemStorage implements IStorageRaw {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
private async getFileHandle(key: string, create: boolean = false): Promise<FileSystemFileHandle | undefined> {
|
|
71
|
+
await this.ensureInitialized();
|
|
71
72
|
try {
|
|
72
73
|
const dirHandle = await this.getDirectoryHandle(create);
|
|
73
74
|
return await dirHandle.getFileHandle(key, { create });
|
|
@@ -77,6 +78,7 @@ export class PrivateFileSystemStorage implements IStorageRaw {
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
private async fileExists(key: string): Promise<boolean> {
|
|
81
|
+
await this.ensureInitialized();
|
|
80
82
|
try {
|
|
81
83
|
// First check if directory exists
|
|
82
84
|
if (!(await this.directoryExists())) {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { observable } from "mobx";
|
|
2
|
+
import { list } from "socket-function/src/misc";
|
|
3
|
+
import { css } from "typesafecss";
|
|
4
|
+
import { URLParam } from "../render-utils/URLParam";
|
|
5
|
+
import { observer } from "../render-utils/observer";
|
|
6
|
+
import * as preact from "preact";
|
|
7
|
+
|
|
8
|
+
const exampleUrlParam = new URLParam("example", "");
|
|
9
|
+
|
|
10
|
+
@observer
|
|
11
|
+
export class ExamplePage extends preact.Component {
|
|
12
|
+
synced = observable({
|
|
13
|
+
count: 0,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
onKeyDown = (e: KeyboardEvent) => {
|
|
17
|
+
// Skip if the current target is an ipnut
|
|
18
|
+
if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let hotkeySelector = `[data-hotkey="${e.code}"]`;
|
|
22
|
+
let elements = document.querySelectorAll(hotkeySelector);
|
|
23
|
+
for (let element of elements) {
|
|
24
|
+
(element as HTMLElement).click();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
componentDidMount(): void {
|
|
28
|
+
document.addEventListener("keydown", this.onKeyDown);
|
|
29
|
+
}
|
|
30
|
+
componentWillUnmount(): void {
|
|
31
|
+
document.removeEventListener("keydown", this.onKeyDown);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
render() {
|
|
35
|
+
return (
|
|
36
|
+
<div className={css.pad2(20)}>
|
|
37
|
+
<h1>Hello from Web! 3</h1>
|
|
38
|
+
<p>Count: {this.synced.count}</p>
|
|
39
|
+
<button onClick={() => this.synced.count++}>
|
|
40
|
+
Increment
|
|
41
|
+
</button>
|
|
42
|
+
<div>
|
|
43
|
+
{list(1000).map(x => <div key={x}>{x}</div>)}
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
package/web/Page.tsx
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import preact from "preact";
|
|
2
|
+
import { css } from "typesafecss";
|
|
3
|
+
import { Anchor } from "../render-utils/Anchor";
|
|
4
|
+
import { URLParam } from "../render-utils/URLParam";
|
|
5
|
+
import { observer } from "../render-utils/observer";
|
|
6
|
+
import { ExamplePage } from "./ExamplePage";
|
|
7
|
+
|
|
8
|
+
export const pageURL = new URLParam("page");
|
|
9
|
+
|
|
10
|
+
@observer
|
|
11
|
+
export class Page extends preact.Component {
|
|
12
|
+
onKeyDown = (e: KeyboardEvent) => {
|
|
13
|
+
// Ignore if it is for an input, text area, etc
|
|
14
|
+
let ignore = (
|
|
15
|
+
e.target instanceof HTMLInputElement ||
|
|
16
|
+
e.target instanceof HTMLTextAreaElement ||
|
|
17
|
+
e.target instanceof HTMLSelectElement
|
|
18
|
+
);
|
|
19
|
+
if (ignore) return;
|
|
20
|
+
|
|
21
|
+
console.log("Checking hotkey", e.key, e);
|
|
22
|
+
let key = e.key;
|
|
23
|
+
if (e.ctrlKey) key = "Ctrl+" + key;
|
|
24
|
+
if (e.shiftKey) key = "Shift+" + key;
|
|
25
|
+
let hotkeyDataAttribute = `[data-hotkey="${key}"]`;
|
|
26
|
+
let el = document.querySelector<HTMLElement>(hotkeyDataAttribute);
|
|
27
|
+
if (el) {
|
|
28
|
+
e.stopPropagation();
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
console.log("Found hotkey", e.key, el);
|
|
31
|
+
el.click();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
render() {
|
|
35
|
+
let pages = [
|
|
36
|
+
{
|
|
37
|
+
key: "example",
|
|
38
|
+
content: <ExamplePage />
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
let page = pages.find(p => p.key === pageURL.value) || pages[0];
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div className={css.size("100vw", "100vh").vbox(0)}>
|
|
46
|
+
<div className={css.hbox(12).pad2(20)}>
|
|
47
|
+
{pages.map(p => (
|
|
48
|
+
<Anchor key={p.key} params={[[pageURL, p.key]]}>
|
|
49
|
+
{p.key}
|
|
50
|
+
</Anchor>
|
|
51
|
+
))}
|
|
52
|
+
</div>
|
|
53
|
+
<div className={css.overflowAuto.fillBoth}>
|
|
54
|
+
{page.content}
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
package/web/browser.tsx
CHANGED
|
@@ -5,53 +5,13 @@ import { css, isNode } from "typesafecss";
|
|
|
5
5
|
import { list } from "socket-function/src/misc";
|
|
6
6
|
import { enableHotReloading } from "../builders/hotReload";
|
|
7
7
|
import { URLParam } from "../render-utils/URLParam";
|
|
8
|
+
import { Page } from "./Page";
|
|
8
9
|
|
|
9
|
-
const exampleUrlParam = new URLParam("example", "");
|
|
10
|
-
|
|
11
|
-
@observer
|
|
12
|
-
class App extends preact.Component {
|
|
13
|
-
synced = observable({
|
|
14
|
-
count: 0,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
onKeyDown = (e: KeyboardEvent) => {
|
|
18
|
-
// Skip if the current target is an ipnut
|
|
19
|
-
if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
let hotkeySelector = `[data-hotkey="${e.code}"]`;
|
|
23
|
-
let elements = document.querySelectorAll(hotkeySelector);
|
|
24
|
-
for (let element of elements) {
|
|
25
|
-
(element as HTMLElement).click();
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
componentDidMount(): void {
|
|
29
|
-
document.addEventListener("keydown", this.onKeyDown);
|
|
30
|
-
}
|
|
31
|
-
componentWillUnmount(): void {
|
|
32
|
-
document.removeEventListener("keydown", this.onKeyDown);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
render() {
|
|
36
|
-
return (
|
|
37
|
-
<div className={css.pad2(20)}>
|
|
38
|
-
<h1>Hello from Web! 3</h1>
|
|
39
|
-
<p>Count: {this.synced.count}</p>
|
|
40
|
-
<button onClick={() => this.synced.count++}>
|
|
41
|
-
Increment
|
|
42
|
-
</button>
|
|
43
|
-
<div>
|
|
44
|
-
{list(1000).map(x => <div key={x}>{x}</div>)}
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
10
|
|
|
51
11
|
async function main() {
|
|
52
12
|
if (isNode()) return;
|
|
53
13
|
await enableHotReloading({ port: 9877 });
|
|
54
|
-
preact.render(<
|
|
14
|
+
preact.render(<Page />, document.getElementById("app")!);
|
|
55
15
|
}
|
|
56
16
|
|
|
57
17
|
main().catch(console.error);
|