brew-js-react 0.2.8 → 0.2.9
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/dialog.d.ts +5 -4
- package/dialog.js +22 -4
- package/dist/brew-js-react.js +1711 -1688
- package/dist/brew-js-react.js.map +1 -1
- package/dist/brew-js-react.min.js +1 -1
- package/dist/brew-js-react.min.js.map +1 -1
- package/entry.js +3 -0
- package/mixins/FlyoutMixin.js +1 -1
- package/package.json +2 -1
package/dialog.d.ts
CHANGED
|
@@ -10,24 +10,25 @@ export interface DialogBaseProps<T> {
|
|
|
10
10
|
title?: string;
|
|
11
11
|
className?: string;
|
|
12
12
|
showCloseButton?: boolean;
|
|
13
|
+
preventLeave?: boolean;
|
|
13
14
|
modal?: boolean;
|
|
14
15
|
onCommit?: (value: T | undefined) => void;
|
|
15
16
|
onOpen?: (root: HTMLElement) => void;
|
|
16
17
|
onClose?: (root: HTMLElement) => void;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
export interface DialogRenderComponentProps<T> extends DialogBaseProps<T
|
|
20
|
+
export interface DialogRenderComponentProps<T, P = {}> extends DialogBaseProps<T>, P {
|
|
20
21
|
closeDialog: DialogCloseCallback<T>;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
export interface DialogOptions<T> extends DialogBaseProps<T> {
|
|
24
|
-
onRender: React.FC<DialogRenderComponentProps<T>>;
|
|
24
|
+
export interface DialogOptions<T, P = {}> extends DialogBaseProps<T> {
|
|
25
|
+
onRender: React.FC<DialogRenderComponentProps<T, P>>;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export interface DialogProps<T> extends React.PropsWithChildren<DialogBaseProps<T>> {
|
|
28
29
|
isOpen: boolean;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
export function createDialog<T = any>(props: DialogOptions<T>): DialogState<T>;
|
|
32
|
+
export function createDialog<T = any, P = {}>(props: DialogOptions<T, P> & { wrapper?: React.FC<React.PropsWithChildren<DialogRenderComponentProps<T, P>>> }): DialogState<T>;
|
|
32
33
|
|
|
33
34
|
export function Dialog<T>(props: DialogProps<T>): JSX.Element;
|
package/dialog.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createElement, useEffect, useState } from "react";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
import { always, catchAsync, either, extend, makeAsync, noop, pipe } from "./include/zeta-dom/util.js";
|
|
4
4
|
import { containsOrEquals, removeNode } from "./include/zeta-dom/domUtil.js";
|
|
5
5
|
import dom from "./include/zeta-dom/dom.js";
|
|
6
|
-
import { lock } from "./include/zeta-dom/domLock.js";
|
|
6
|
+
import { lock, preventLeave } from "./include/zeta-dom/domLock.js";
|
|
7
7
|
import { closeFlyout, openFlyout } from "./include/brew-js/domAction.js";
|
|
8
8
|
|
|
9
|
+
const createRoot = ReactDOM.createRoot;
|
|
10
|
+
|
|
9
11
|
/**
|
|
10
12
|
* @param {Partial<import("./dialog").DialogOptions<any>>} props
|
|
11
13
|
*/
|
|
12
14
|
export function createDialog(props) {
|
|
13
15
|
var root = document.createElement('div');
|
|
16
|
+
var reactRoot = createRoot && createRoot(root);
|
|
14
17
|
var closing = false;
|
|
15
18
|
var promise;
|
|
16
19
|
|
|
@@ -22,7 +25,11 @@ export function createDialog(props) {
|
|
|
22
25
|
removeNode(root);
|
|
23
26
|
(props.onClose || noop)(root);
|
|
24
27
|
if (props.onRender) {
|
|
25
|
-
|
|
28
|
+
if (reactRoot) {
|
|
29
|
+
reactRoot.unmount();
|
|
30
|
+
} else {
|
|
31
|
+
ReactDOM.unmountComponentAtNode(root);
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
34
|
});
|
|
28
35
|
}
|
|
@@ -50,9 +57,20 @@ export function createDialog(props) {
|
|
|
50
57
|
promise.then(closeDialog, noop);
|
|
51
58
|
}
|
|
52
59
|
});
|
|
53
|
-
|
|
60
|
+
var content = createElement(props.onRender, dialogProps);
|
|
61
|
+
if (props.wrapper) {
|
|
62
|
+
content = createElement(props.wrapper, dialogProps, content);
|
|
63
|
+
}
|
|
64
|
+
if (reactRoot) {
|
|
65
|
+
reactRoot.render(content);
|
|
66
|
+
} else {
|
|
67
|
+
ReactDOM.render(content, root);
|
|
68
|
+
}
|
|
54
69
|
}
|
|
55
70
|
promise = openFlyout(root);
|
|
71
|
+
if (props.preventLeave) {
|
|
72
|
+
preventLeave(root, promise);
|
|
73
|
+
}
|
|
56
74
|
always(promise, function () {
|
|
57
75
|
promise = null;
|
|
58
76
|
});
|