sliftutils 0.44.0 → 0.46.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(contents: preact.ComponentChildren): void;
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,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "0.44.0",
3
+ "version": "0.46.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -1,5 +1,8 @@
1
1
  import preact from "preact";
2
- export declare function showFullscreenModal(contents: preact.ComponentChildren): void;
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(contents: preact.ComponentChildren) {
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
 
@@ -1,6 +1,7 @@
1
1
  import preact from "preact";
2
2
  export declare function showModal(config: {
3
3
  contents: preact.ComponentChildren;
4
+ onClose?: () => void;
4
5
  }): {
5
6
  close: () => void;
6
7
  };
@@ -4,16 +4,21 @@ import * as mobx from "mobx";
4
4
  import { observer } from "./observer";
5
5
  import { lazy } from "socket-function/src/caching";
6
6
 
7
- const activeModals = observable({} as { [key: string]: preact.ComponentChildren }, undefined, { deep: false });
7
+ type ModalData = {
8
+ contents: preact.ComponentChildren;
9
+ onClose?: () => void;
10
+ };
11
+
12
+ const activeModals = observable({} as { [key: string]: ModalData }, undefined, { deep: false });
8
13
 
9
14
  @observer
10
15
  class ModalRoot extends preact.Component {
11
16
  render() {
12
- const modals: Array<[string, preact.ComponentChildren]> = Object.entries(activeModals);
13
- return <div>
14
- {modals.map(([id, contents]) => (
17
+ const modals: Array<[string, ModalData]> = Object.entries(activeModals);
18
+ return <div style={{ position: "relative", zIndex: 1 }}>
19
+ {modals.map(([id, data]) => (
15
20
  <div key={id}>
16
- {contents}
21
+ {data.contents}
17
22
  </div>
18
23
  ))}
19
24
  </div>;
@@ -28,25 +33,42 @@ const ensureRootMounted = lazy(() => {
28
33
 
29
34
  let modalIdCounter = 0;
30
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
+
31
49
  export function showModal(config: {
32
50
  contents: preact.ComponentChildren;
51
+ onClose?: () => void;
33
52
  }): {
34
53
  close: () => void;
35
54
  } {
36
55
  ensureRootMounted();
37
56
 
38
57
  const id = `modal-${modalIdCounter++}`;
39
- activeModals[id] = config.contents;
58
+ activeModals[id] = {
59
+ contents: config.contents,
60
+ onClose: config.onClose
61
+ };
40
62
 
41
63
  return {
42
64
  close() {
43
- delete activeModals[id];
65
+ closeModal(id);
44
66
  }
45
67
  };
46
68
  }
47
69
 
48
70
  export function closeAllModals() {
49
71
  for (let key in activeModals) {
50
- delete activeModals[key];
72
+ closeModal(key);
51
73
  }
52
74
  }
package/web/Page.tsx CHANGED
@@ -12,7 +12,7 @@ export class Page extends preact.Component {
12
12
  onKeyDown = (e: KeyboardEvent) => {
13
13
  // Ignore if it is for an input, text area, etc
14
14
  let ignore = (
15
- e.target instanceof HTMLInputElement ||
15
+ e.target instanceof HTMLInputElement && e.target.type !== "file" ||
16
16
  e.target instanceof HTMLTextAreaElement ||
17
17
  e.target instanceof HTMLSelectElement
18
18
  );
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