brew-js-react 0.5.7 → 0.6.1

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/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  Brew.js for React is a utility that allow brew.js features to be used on React App.
4
4
 
5
- See documentation at https://hackmd.io/@misonou/brew-js-react.
5
+ See documentation at https://misonou.github.io.
package/dialog.d.ts CHANGED
@@ -64,7 +64,7 @@ export interface DialogBaseProps<T, V = T> {
64
64
  * The dialog will be held open until the returned promise resolves.
65
65
  * When the promise rejects, the dialog will remain open.
66
66
  */
67
- onCommit?: (value: V | undefined) => T | Promise<T> | void;
67
+ onCommit?: (value: V | undefined, context: Zeta.RunAsyncContext) => T | Promise<T> | void;
68
68
  /**
69
69
  * Callback to be invoked when dialog has opened.
70
70
  */
package/dialog.js CHANGED
@@ -1,10 +1,10 @@
1
- import { createElement, useEffect, useState } from "react";
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 { either, extend, makeAsync, noop, pick, pipe, resolve } from "zeta-dom/util";
4
+ import { either, extend, noop, pick, resolve } from "zeta-dom/util";
5
5
  import { containsOrEquals, removeNode } from "zeta-dom/domUtil";
6
6
  import dom from "zeta-dom/dom";
7
- import { lock, notifyAsync, preventLeave, subscribeAsync } from "zeta-dom/domLock";
7
+ import { lock, preventLeave, runAsync, subscribeAsync } from "zeta-dom/domLock";
8
8
  import { closeFlyout, openFlyout } from "brew-js/domAction";
9
9
 
10
10
  /**
@@ -41,25 +41,23 @@ export function createDialog(props) {
41
41
  }
42
42
  root.className = props.className || '';
43
43
  document.body.appendChild(root);
44
- dom.retainFocus(dom.activeElement, root);
45
44
  if (props.modal) {
46
45
  root.setAttribute('is-modal', '');
47
46
  }
48
47
  if (props.onRender) {
49
48
  var dialogProps = extend({}, props, {
50
- closeDialog: function (value) {
51
- var promise = makeAsync(props.onCommit || pipe)(value);
52
- notifyAsync(dom.activeElement, promise);
53
- return promise.then(closeDialog);
54
- }
49
+ closeDialog: props.onCommit ? function (value) {
50
+ return runAsync(dom.activeElement, props.onCommit.bind(this, value)).then(closeDialog);
51
+ } : closeDialog
55
52
  });
56
53
  var content = createElement(props.onRender, dialogProps);
57
54
  if (props.wrapper) {
58
55
  content = createElement(props.wrapper, dialogProps, content);
59
56
  }
60
- reactRoot.render(content);
57
+ reactRoot.render(createElement(StrictMode, null, content));
61
58
  }
62
59
  promise = resolve().then(function () {
60
+ dom.retainFocus(dom.activeElement, root);
63
61
  return openFlyout(root, null, pick(props, ['focus']));
64
62
  });
65
63
  if (props.preventLeave) {