sliftutils 0.42.0 → 0.44.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/.cursorrules +6 -0
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/render-utils/modal.d.ts +1 -0
- package/render-utils/modal.tsx +39 -5
- package/web/Page.tsx +6 -0
package/.cursorrules
CHANGED
|
@@ -79,6 +79,12 @@ Coding Styles
|
|
|
79
79
|
|
|
80
80
|
Do not try catch for no reason. If you can't actually handle the exception, just let it throw.
|
|
81
81
|
|
|
82
|
+
For input events, always use event.currentTarget.
|
|
83
|
+
|
|
84
|
+
Use ref={elem => } callbacks. NEVER use .createRef.
|
|
85
|
+
|
|
86
|
+
NEVER render images with a fixed width+height. This will cause them to be stretched or cut off. This is terrible. Only set the width or height.
|
|
87
|
+
|
|
82
88
|
|
|
83
89
|
|
|
84
90
|
General Styling
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/render-utils/modal.d.ts
CHANGED
package/render-utils/modal.tsx
CHANGED
|
@@ -1,18 +1,52 @@
|
|
|
1
1
|
import preact from "preact";
|
|
2
|
+
import { observable } from "mobx";
|
|
3
|
+
import * as mobx from "mobx";
|
|
4
|
+
import { observer } from "./observer";
|
|
5
|
+
import { lazy } from "socket-function/src/caching";
|
|
6
|
+
|
|
7
|
+
const activeModals = observable({} as { [key: string]: preact.ComponentChildren }, undefined, { deep: false });
|
|
8
|
+
|
|
9
|
+
@observer
|
|
10
|
+
class ModalRoot extends preact.Component {
|
|
11
|
+
render() {
|
|
12
|
+
const modals: Array<[string, preact.ComponentChildren]> = Object.entries(activeModals);
|
|
13
|
+
return <div>
|
|
14
|
+
{modals.map(([id, contents]) => (
|
|
15
|
+
<div key={id}>
|
|
16
|
+
{contents}
|
|
17
|
+
</div>
|
|
18
|
+
))}
|
|
19
|
+
</div>;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ensureRootMounted = lazy(() => {
|
|
24
|
+
const root = document.createElement("div");
|
|
25
|
+
document.body.appendChild(root);
|
|
26
|
+
preact.render(<ModalRoot />, root);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
let modalIdCounter = 0;
|
|
2
30
|
|
|
3
31
|
export function showModal(config: {
|
|
4
32
|
contents: preact.ComponentChildren;
|
|
5
33
|
}): {
|
|
6
34
|
close: () => void;
|
|
7
35
|
} {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
36
|
+
ensureRootMounted();
|
|
37
|
+
|
|
38
|
+
const id = `modal-${modalIdCounter++}`;
|
|
39
|
+
activeModals[id] = config.contents;
|
|
11
40
|
|
|
12
41
|
return {
|
|
13
42
|
close() {
|
|
14
|
-
|
|
15
|
-
document.body.removeChild(root);
|
|
43
|
+
delete activeModals[id];
|
|
16
44
|
}
|
|
17
45
|
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function closeAllModals() {
|
|
49
|
+
for (let key in activeModals) {
|
|
50
|
+
delete activeModals[key];
|
|
51
|
+
}
|
|
18
52
|
}
|
package/web/Page.tsx
CHANGED
|
@@ -31,6 +31,12 @@ export class Page extends preact.Component {
|
|
|
31
31
|
el.click();
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
+
componentDidMount() {
|
|
35
|
+
document.addEventListener("keydown", this.onKeyDown);
|
|
36
|
+
}
|
|
37
|
+
componentWillUnmount() {
|
|
38
|
+
document.removeEventListener("keydown", this.onKeyDown);
|
|
39
|
+
}
|
|
34
40
|
render() {
|
|
35
41
|
let pages = [
|
|
36
42
|
{
|