sliftutils 0.43.0 → 0.45.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/index.d.ts
CHANGED
|
@@ -169,7 +169,10 @@ declare module "sliftutils/render-utils/DropdownCustom" {
|
|
|
169
169
|
|
|
170
170
|
declare module "sliftutils/render-utils/FullscreenModal" {
|
|
171
171
|
import preact from "preact";
|
|
172
|
-
export declare function showFullscreenModal(
|
|
172
|
+
export declare function showFullscreenModal(config: {
|
|
173
|
+
contents: preact.ComponentChildren;
|
|
174
|
+
onClose?: () => void;
|
|
175
|
+
}): void;
|
|
173
176
|
export declare class FullscreenModal extends preact.Component<{
|
|
174
177
|
parentState?: {
|
|
175
178
|
open: boolean;
|
|
@@ -449,6 +452,7 @@ declare module "sliftutils/render-utils/modal" {
|
|
|
449
452
|
import preact from "preact";
|
|
450
453
|
export declare function showModal(config: {
|
|
451
454
|
contents: preact.ComponentChildren;
|
|
455
|
+
onClose?: () => void;
|
|
452
456
|
}): {
|
|
453
457
|
close: () => void;
|
|
454
458
|
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import preact from "preact";
|
|
2
|
-
export declare function showFullscreenModal(
|
|
2
|
+
export declare function showFullscreenModal(config: {
|
|
3
|
+
contents: preact.ComponentChildren;
|
|
4
|
+
onClose?: () => void;
|
|
5
|
+
}): void;
|
|
3
6
|
export declare class FullscreenModal extends preact.Component<{
|
|
4
7
|
parentState?: {
|
|
5
8
|
open: boolean;
|
|
@@ -3,11 +3,15 @@ import { showModal } from "./modal";
|
|
|
3
3
|
import { observable } from "mobx";
|
|
4
4
|
import { observer } from "./observer";
|
|
5
5
|
|
|
6
|
-
export function showFullscreenModal(
|
|
6
|
+
export function showFullscreenModal(config: {
|
|
7
|
+
contents: preact.ComponentChildren;
|
|
8
|
+
onClose?: () => void;
|
|
9
|
+
}) {
|
|
7
10
|
let { close } = showModal({
|
|
8
11
|
contents: <FullscreenModal onCancel={() => close()}>
|
|
9
|
-
{contents}
|
|
10
|
-
</FullscreenModal
|
|
12
|
+
{config.contents}
|
|
13
|
+
</FullscreenModal>,
|
|
14
|
+
onClose: config.onClose
|
|
11
15
|
});
|
|
12
16
|
}
|
|
13
17
|
|
package/render-utils/modal.d.ts
CHANGED
package/render-utils/modal.tsx
CHANGED
|
@@ -4,20 +4,24 @@ import * as mobx from "mobx";
|
|
|
4
4
|
import { observer } from "./observer";
|
|
5
5
|
import { lazy } from "socket-function/src/caching";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
type ModalData = {
|
|
8
|
+
contents: preact.ComponentChildren;
|
|
9
|
+
onClose?: () => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const activeModals = observable({} as { [key: string]: ModalData }, undefined, { deep: false });
|
|
9
13
|
|
|
10
14
|
@observer
|
|
11
15
|
class ModalRoot extends preact.Component {
|
|
12
16
|
render() {
|
|
13
|
-
const modals: Array<[string,
|
|
14
|
-
return
|
|
15
|
-
{modals.map(([id,
|
|
17
|
+
const modals: Array<[string, ModalData]> = Object.entries(activeModals);
|
|
18
|
+
return <div>
|
|
19
|
+
{modals.map(([id, data]) => (
|
|
16
20
|
<div key={id}>
|
|
17
|
-
{contents}
|
|
21
|
+
{data.contents}
|
|
18
22
|
</div>
|
|
19
23
|
))}
|
|
20
|
-
|
|
24
|
+
</div>;
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
|
|
@@ -29,23 +33,42 @@ const ensureRootMounted = lazy(() => {
|
|
|
29
33
|
|
|
30
34
|
let modalIdCounter = 0;
|
|
31
35
|
|
|
36
|
+
function closeModal(id: string) {
|
|
37
|
+
const modal = activeModals[id];
|
|
38
|
+
if (!modal) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
delete activeModals[id];
|
|
43
|
+
|
|
44
|
+
if (modal.onClose) {
|
|
45
|
+
modal.onClose();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
32
49
|
export function showModal(config: {
|
|
33
50
|
contents: preact.ComponentChildren;
|
|
51
|
+
onClose?: () => void;
|
|
34
52
|
}): {
|
|
35
53
|
close: () => void;
|
|
36
54
|
} {
|
|
37
55
|
ensureRootMounted();
|
|
38
56
|
|
|
39
57
|
const id = `modal-${modalIdCounter++}`;
|
|
40
|
-
activeModals
|
|
58
|
+
activeModals[id] = {
|
|
59
|
+
contents: config.contents,
|
|
60
|
+
onClose: config.onClose
|
|
61
|
+
};
|
|
41
62
|
|
|
42
63
|
return {
|
|
43
64
|
close() {
|
|
44
|
-
|
|
65
|
+
closeModal(id);
|
|
45
66
|
}
|
|
46
67
|
};
|
|
47
68
|
}
|
|
48
69
|
|
|
49
70
|
export function closeAllModals() {
|
|
50
|
-
activeModals
|
|
71
|
+
for (let key in activeModals) {
|
|
72
|
+
closeModal(key);
|
|
73
|
+
}
|
|
51
74
|
}
|
package/web/browser.tsx
CHANGED
|
@@ -6,11 +6,13 @@ import { list } from "socket-function/src/misc";
|
|
|
6
6
|
import { enableHotReloading } from "../builders/hotReload";
|
|
7
7
|
import { URLParam } from "../render-utils/URLParam";
|
|
8
8
|
import { Page } from "./Page";
|
|
9
|
+
import { configureMobxNextFrameScheduler } from "sliftutils/render-utils/mobxTyped";
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
async function main() {
|
|
12
13
|
if (isNode()) return;
|
|
13
14
|
await enableHotReloading({ port: 9877 });
|
|
15
|
+
configureMobxNextFrameScheduler();
|
|
14
16
|
preact.render(<Page />, document.getElementById("app")!);
|
|
15
17
|
}
|
|
16
18
|
|