brew-js-react 0.6.3 → 0.6.5
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 +57 -21
- package/dialog.js +10 -4
- package/dist/brew-js-react.js +172 -134
- package/dist/brew-js-react.js.map +1 -1
- package/dist/brew-js-react.min.js +2 -2
- package/dist/brew-js-react.min.js.map +1 -1
- package/i18n.d.ts +34 -47
- package/mixins/ClassNameMixin.d.ts +1 -1
- package/mixins/ScrollableMixin.d.ts +3 -1
- package/mixins/StaticAttributeMixin.d.ts +1 -1
- package/package.json +6 -4
- package/view.d.ts +72 -13
- package/view.js +127 -104
package/dialog.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { ErrorHandler } from "zeta-dom-react";
|
|
2
|
+
|
|
3
|
+
type PartialRequired<T, K extends keyof T> = Omit<T, K> & { [P in K]-?: T[P] }
|
|
4
|
+
type VoidOrOptional<T> = [Exclude<T, undefined | void>] extends [never] ? void : Exclude<T, undefined | void>;
|
|
5
|
+
|
|
6
|
+
export type DialogCloseCallback<T> = Zeta.IsAnyOrUnknown<T> extends true ?
|
|
7
|
+
(value?: any) => Promise<void> :
|
|
8
|
+
(value: T extends undefined ? void | undefined : T) => Promise<void>;
|
|
9
|
+
export type DialogResult<T> = T extends void ? undefined : Zeta.IsAnyOrUnknown<T> extends true ? any : T | undefined;
|
|
10
|
+
export type DialogOptionsStrict<T, V> = PartialRequired<DialogOptions<T, V>, 'onCommit'>;
|
|
11
|
+
|
|
12
|
+
/** @deprecated */
|
|
13
|
+
export type DialogBaseProps<T, V = T> = Omit<DialogOptions<T, V | undefined>, 'onRender' | 'wrapper'>;
|
|
14
|
+
/** @deprecated */
|
|
15
|
+
export type DialogRenderComponentProps<T, V = T> = DialogOptions<T, V | undefined> & DialogContext<V | undefined>;
|
|
2
16
|
|
|
3
17
|
export interface DialogState<T> {
|
|
4
18
|
/**
|
|
@@ -8,19 +22,19 @@ export interface DialogState<T> {
|
|
|
8
22
|
/**
|
|
9
23
|
* Opens the dialog.
|
|
10
24
|
*
|
|
11
|
-
* It will receive result from {@link DialogState.close} or {@link
|
|
25
|
+
* It will receive result from {@link DialogState.close} or {@link DialogContext.closeDialog} when the dialog is properly closed.
|
|
12
26
|
* Otherwise in cases such as being closed due to lost of focus, result value will always be `undefined`.
|
|
13
27
|
*/
|
|
14
|
-
open
|
|
28
|
+
open(): Promise<DialogResult<T>>;
|
|
15
29
|
/**
|
|
16
30
|
* Closes the dialog, with optional result value.
|
|
17
31
|
*
|
|
18
|
-
* This method is
|
|
32
|
+
* This method is similar to {@link DialogContext.dismissDialog} that {@link DialogOptions.onCommit} will not be called.
|
|
19
33
|
*/
|
|
20
|
-
close
|
|
34
|
+
close(value?: T): Promise<void>;
|
|
21
35
|
}
|
|
22
36
|
|
|
23
|
-
export interface
|
|
37
|
+
export interface DialogOptions<T, V = T | undefined> {
|
|
24
38
|
/**
|
|
25
39
|
* Specifies dialog title.
|
|
26
40
|
* This property is intended to be handled by {@link DialogOptions.onRender} or {@link DialogOptions.wrapper}.
|
|
@@ -58,13 +72,13 @@ export interface DialogBaseProps<T, V = T> {
|
|
|
58
72
|
/**
|
|
59
73
|
* Callback to perform asynchronous action when user confirms the dialog.
|
|
60
74
|
*
|
|
61
|
-
* The callback will receive value sent from {@link
|
|
75
|
+
* The callback will receive value sent from {@link DialogContext.commitDialog} or {@link DialogContext.closeDialog},
|
|
62
76
|
* and will send resolved value to promise returned by {@link DialogState.open}.
|
|
63
77
|
*
|
|
64
78
|
* The dialog will be held open until the returned promise resolves.
|
|
65
79
|
* When the promise rejects, the dialog will remain open.
|
|
66
80
|
*/
|
|
67
|
-
onCommit?: (value: V
|
|
81
|
+
onCommit?: (value: V, context: Zeta.RunAsyncContext) => T | Promise<T> | undefined | void;
|
|
68
82
|
/**
|
|
69
83
|
* Callback to be invoked when dialog has opened.
|
|
70
84
|
*/
|
|
@@ -73,28 +87,42 @@ export interface DialogBaseProps<T, V = T> {
|
|
|
73
87
|
* Callback to be invoked when dialog has closed, after outro animation and before React DOM is unmounted.
|
|
74
88
|
*/
|
|
75
89
|
onClose?: (root: HTMLElement) => void;
|
|
90
|
+
/**
|
|
91
|
+
* A callback that render dialog contents.
|
|
92
|
+
*/
|
|
93
|
+
onRender: React.VFC<DialogContext<V> & this>;
|
|
94
|
+
/**
|
|
95
|
+
* Specifies wrapper component that envelops content from {@link DialogOptions.onRender},
|
|
96
|
+
* which is useful for reusable layout for dialogs.
|
|
97
|
+
*/
|
|
98
|
+
wrapper?: React.FC<DialogContext<V> & this & React.PropsWithChildren<{}>>;
|
|
76
99
|
}
|
|
77
100
|
|
|
78
|
-
export interface
|
|
101
|
+
export interface DialogContext<V> {
|
|
102
|
+
/**
|
|
103
|
+
* Gets an {@link ErrorHandler} object that catches errors emitted from rendered content.
|
|
104
|
+
*/
|
|
105
|
+
errorHandler: ErrorHandler;
|
|
79
106
|
/**
|
|
80
|
-
* Commits the dialog
|
|
107
|
+
* Commits the dialog with result value.
|
|
81
108
|
*
|
|
82
|
-
* When {@link
|
|
109
|
+
* When {@link DialogOptions.onCommit} is specified, it is invoked with the value passed in.
|
|
83
110
|
* Dialog will be closed when async operation is completed, or remain open if the operation failed.
|
|
111
|
+
*
|
|
112
|
+
* @deprecated Alias of {@link DialogContext.commitDialog}.
|
|
84
113
|
*/
|
|
85
|
-
closeDialog:
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface DialogOptions<T, V = T> extends DialogBaseProps<T, V> {
|
|
114
|
+
closeDialog: DialogCloseCallback<V>;
|
|
89
115
|
/**
|
|
90
|
-
*
|
|
116
|
+
* Commits the dialog with result value.
|
|
117
|
+
*
|
|
118
|
+
* When {@link DialogOptions.onCommit} is specified, it is invoked with the value passed in.
|
|
119
|
+
* Dialog will be closed when async operation is completed, or remain open if the operation failed.
|
|
91
120
|
*/
|
|
92
|
-
|
|
121
|
+
commitDialog: DialogCloseCallback<V>;
|
|
93
122
|
/**
|
|
94
|
-
*
|
|
95
|
-
* which is useful for reusable layout for dialogs.
|
|
123
|
+
* Closes the dialog without invoking {@link DialogOptions.onCommit}.
|
|
96
124
|
*/
|
|
97
|
-
|
|
125
|
+
dismissDialog: DialogCloseCallback<void>;
|
|
98
126
|
}
|
|
99
127
|
|
|
100
128
|
export interface DialogProps<T, V = T> extends React.PropsWithChildren<DialogBaseProps<T, V>> {
|
|
@@ -108,7 +136,15 @@ export interface DialogProps<T, V = T> extends React.PropsWithChildren<DialogBas
|
|
|
108
136
|
* Creates a controller to render dialog.
|
|
109
137
|
* @param props A dictionary containing options.
|
|
110
138
|
*/
|
|
111
|
-
export function createDialog<T
|
|
139
|
+
export function createDialog<T, V>(props: DialogOptionsStrict<T, V>): DialogState<VoidOrOptional<T>>;
|
|
140
|
+
|
|
141
|
+
export function createDialog<T, V>(props: DialogOptions<T, V>): DialogState<VoidOrOptional<T | V>>;
|
|
142
|
+
|
|
143
|
+
export function createDialog<T, V = T>(props: DialogOptions<T, V | undefined>): DialogState<VoidOrOptional<T | V>>;
|
|
144
|
+
|
|
145
|
+
export function createDialog<P extends DialogOptionsStrict<any, any>>(props: P): DialogState<VoidOrOptional<P extends DialogOptionsStrict<infer T, any> ? T : unknown>>;
|
|
146
|
+
|
|
147
|
+
export function createDialog<P extends DialogOptions<any, any>>(props: P): DialogState<VoidOrOptional<P extends DialogOptions<infer T, infer V> ? T | V : unknown>>;
|
|
112
148
|
|
|
113
149
|
/**
|
|
114
150
|
* Renders a dialog declaratively.
|
package/dialog.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createElement, StrictMode, useEffect, useState } from "react";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
3
|
import ReactDOMClient from "@misonou/react-dom-client";
|
|
4
|
+
import { createAsyncScope } from "zeta-dom-react";
|
|
4
5
|
import { either, extend, noop, pick, resolve } from "zeta-dom/util";
|
|
5
6
|
import { containsOrEquals, removeNode } from "zeta-dom/domUtil";
|
|
6
7
|
import dom from "zeta-dom/dom";
|
|
@@ -13,6 +14,7 @@ import { closeFlyout, openFlyout } from "brew-js/domAction";
|
|
|
13
14
|
export function createDialog(props) {
|
|
14
15
|
var root = document.createElement('div');
|
|
15
16
|
var reactRoot = ReactDOMClient.createRoot(root);
|
|
17
|
+
var scope = createAsyncScope(root);
|
|
16
18
|
var closeDialog = closeFlyout.bind(0, root);
|
|
17
19
|
var promise;
|
|
18
20
|
|
|
@@ -45,16 +47,20 @@ export function createDialog(props) {
|
|
|
45
47
|
root.setAttribute('is-modal', '');
|
|
46
48
|
}
|
|
47
49
|
if (props.onRender) {
|
|
50
|
+
var commitDialog = props.onCommit ? function (value) {
|
|
51
|
+
return runAsync(dom.activeElement, props.onCommit.bind(this, value)).then(closeDialog);
|
|
52
|
+
} : closeDialog;
|
|
48
53
|
var dialogProps = extend({}, props, {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
errorHandler: scope.errorHandler,
|
|
55
|
+
closeDialog: commitDialog,
|
|
56
|
+
commitDialog: commitDialog,
|
|
57
|
+
dismissDialog: closeDialog
|
|
52
58
|
});
|
|
53
59
|
var content = createElement(props.onRender, dialogProps);
|
|
54
60
|
if (props.wrapper) {
|
|
55
61
|
content = createElement(props.wrapper, dialogProps, content);
|
|
56
62
|
}
|
|
57
|
-
reactRoot.render(createElement(StrictMode, null, content));
|
|
63
|
+
reactRoot.render(createElement(StrictMode, null, createElement(scope.Provider, null, content)));
|
|
58
64
|
}
|
|
59
65
|
promise = resolve().then(function () {
|
|
60
66
|
dom.retainFocus(dom.activeElement, root);
|