brew-js-react 0.6.0 → 0.6.2

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.js CHANGED
@@ -1,4 +1,4 @@
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
4
  import { either, extend, noop, pick, resolve } from "zeta-dom/util";
@@ -41,7 +41,6 @@ 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
  }
@@ -55,9 +54,10 @@ export function createDialog(props) {
55
54
  if (props.wrapper) {
56
55
  content = createElement(props.wrapper, dialogProps, content);
57
56
  }
58
- reactRoot.render(content);
57
+ reactRoot.render(createElement(StrictMode, null, content));
59
58
  }
60
59
  promise = resolve().then(function () {
60
+ dom.retainFocus(dom.activeElement, root);
61
61
  return openFlyout(root, null, pick(props, ['focus']));
62
62
  });
63
63
  if (props.preventLeave) {
@@ -1,4 +1,4 @@
1
- /*! brew-js-react v0.6.0 | (c) misonou | https://misonou.github.io */
1
+ /*! brew-js-react v0.6.2 | (c) misonou | https://misonou.github.io */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("zeta-dom"), require("react"), require("react-dom"), require("brew-js"), require("zeta-dom-react"), require("waterpipe"), require("jquery"));
@@ -270,6 +270,7 @@ var external_commonjs_react_commonjs2_react_amd_react_root_React_ = __webpack_re
270
270
 
271
271
  var Component = external_commonjs_react_commonjs2_react_amd_react_root_React_.Component,
272
272
  Fragment = external_commonjs_react_commonjs2_react_amd_react_root_React_.Fragment,
273
+ StrictMode = external_commonjs_react_commonjs2_react_amd_react_root_React_.StrictMode,
273
274
  createContext = external_commonjs_react_commonjs2_react_amd_react_root_React_.createContext,
274
275
  createElement = external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement,
275
276
  useContext = external_commonjs_react_commonjs2_react_amd_react_root_React_.useContext,
@@ -311,6 +312,7 @@ var external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_ = __webpa
311
312
  ;// CONCATENATED MODULE: ./|umd|/brew-js/domAction.js
312
313
 
313
314
  var closeFlyout = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.closeFlyout,
315
+ isFlyoutOpen = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.isFlyoutOpen,
314
316
  openFlyout = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.openFlyout,
315
317
  toggleFlyout = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.toggleFlyout;
316
318
 
@@ -356,7 +358,6 @@ function createDialog(props) {
356
358
  }
357
359
  root.className = props.className || '';
358
360
  document.body.appendChild(root);
359
- zeta_dom_dom.retainFocus(zeta_dom_dom.activeElement, root);
360
361
  if (props.modal) {
361
362
  root.setAttribute('is-modal', '');
362
363
  }
@@ -370,9 +371,10 @@ function createDialog(props) {
370
371
  if (props.wrapper) {
371
372
  content = /*#__PURE__*/createElement(props.wrapper, dialogProps, content);
372
373
  }
373
- reactRoot.render(content);
374
+ reactRoot.render( /*#__PURE__*/createElement(StrictMode, null, content));
374
375
  }
375
376
  promise = resolve().then(function () {
377
+ zeta_dom_dom.retainFocus(zeta_dom_dom.activeElement, root);
376
378
  return openFlyout(root, null, pick(props, ['focus']));
377
379
  });
378
380
  if (props.preventLeave) {
@@ -416,6 +418,7 @@ var external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react
416
418
  var ViewStateProvider = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.ViewStateProvider,
417
419
  classNames = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.classNames,
418
420
  useAsync = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useAsync,
421
+ useEagerState = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useEagerState,
419
422
  useMemoizedFunction = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useMemoizedFunction,
420
423
  useObservableProperty = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useObservableProperty,
421
424
  useSingleton = external_commonjs_zeta_dom_react_commonjs2_zeta_dom_react_amd_zeta_dom_react_root_zeta_react_.useSingleton,
@@ -496,23 +499,16 @@ onAppInit(function () {
496
499
  rootState.setPage(app_app.page);
497
500
  rootState.setActive(true);
498
501
  view_event = e;
499
- e.waitFor(new Promise(function (resolve) {
500
- (function updateViewRecursive(next) {
501
- if (!next[0]) {
502
- return resolve();
503
- }
504
- resolveAll(map(next, function (v) {
505
- return new Promise(function (resolve) {
506
- v.onRender = resolve;
507
- v.forceUpdate();
508
- });
509
- })).then(function () {
510
- updateViewRecursive(map(next, function (v) {
511
- return v.children;
512
- }));
513
- });
514
- })(rootState.children);
515
- }));
502
+ (function updateViewRecursive(next) {
503
+ each(next.children, function (i, v) {
504
+ e.waitFor(new Promise(function (resolve) {
505
+ v.onRender = resolve;
506
+ v.forceUpdate();
507
+ }).then(function () {
508
+ updateViewRecursive(v);
509
+ }));
510
+ });
511
+ })(rootState);
516
512
  });
517
513
  });
518
514
  function ViewContext(view, page, parent) {
@@ -958,7 +954,7 @@ function useRouteParam(name, defaultValue) {
958
954
  }
959
955
  function useRouteState(key, defaultValue, snapshotOnUpdate) {
960
956
  var cur = getCurrentStates();
961
- var state = useState(cur && cur.has(key) ? cur.get(key) : defaultValue);
957
+ var state = useEagerState(cur && cur.has(key) ? cur.get(key) : defaultValue);
962
958
  var container = useViewContextWithEffect(function (cur) {
963
959
  state[1](function (oldValue) {
964
960
  return cur.has(key) ? cur.get(key) : (cur.set(key, oldValue), oldValue);
@@ -1499,8 +1495,8 @@ definePrototype(FlyoutToggleMixin, ClassNameMixin, {
1499
1495
  close: function close(value) {
1500
1496
  return this.flyoutMixin.close(value);
1501
1497
  },
1502
- toggle: function toggle(source) {
1503
- return this.flyoutMixin.toggleSelf(source);
1498
+ toggle: function toggle(flag, source) {
1499
+ return this.flyoutMixin.toggleSelf(flag, source);
1504
1500
  },
1505
1501
  initElement: function initElement(element, state) {
1506
1502
  var self = this;
@@ -1526,6 +1522,13 @@ definePrototype(FlyoutToggleMixin, ClassNameMixin, {
1526
1522
 
1527
1523
  var FlyoutMixinSuper = ClassNameMixin.prototype;
1528
1524
  var valueMap = new WeakMap();
1525
+ function _toggleSelf(self, flag, value, source) {
1526
+ if (!flag && !isFlyoutOpen(self.element)) {
1527
+ return resolve();
1528
+ }
1529
+ var options = self.getOptions();
1530
+ return flag ? openFlyout(self.element, value, source, options) : toggleFlyout(self.element, source, options);
1531
+ }
1529
1532
  function FlyoutMixin() {
1530
1533
  var self = this;
1531
1534
  ClassNameMixin.call(self, ['open', 'closing', 'visible', 'tweening-in', 'tweening-out']);
@@ -1548,7 +1551,7 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1548
1551
  },
1549
1552
  getOptions: function getOptions() {
1550
1553
  var self = this;
1551
- var options = pick(self, ['closeOnBlur']);
1554
+ var options = pick(self, ['closeOnBlur', 'containment']);
1552
1555
  if (self.initialFocus !== undefined) {
1553
1556
  options.focus = self.initialFocus;
1554
1557
  }
@@ -1578,13 +1581,17 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1578
1581
  });
1579
1582
  },
1580
1583
  open: function open(value, source) {
1581
- return openFlyout(this.element, value, source, this.getOptions());
1584
+ return _toggleSelf(this, true, value, source);
1582
1585
  },
1583
1586
  close: function close(value) {
1584
1587
  return closeFlyout(this.element, value);
1585
1588
  },
1586
- toggleSelf: function toggleSelf(source) {
1587
- return toggleFlyout(this.element, source, this.getOptions());
1589
+ toggleSelf: function toggleSelf(flag, source) {
1590
+ if (typeof flag !== 'boolean') {
1591
+ source = flag;
1592
+ flag = !isFlyoutOpen(this.element);
1593
+ }
1594
+ return _toggleSelf(this, flag, undefined, source);
1588
1595
  },
1589
1596
  onOpen: function onOpen(callback) {
1590
1597
  return this.onToggleState(function (opened) {