brew-js-react 0.7.3 → 0.7.4

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 CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ErrorHandler } from "zeta-dom-react";
2
2
 
3
+ type VFC<P = {}> = (props: P) => ReturnType<React.FC>;
3
4
  type PartialRequired<T, K extends keyof T> = Omit<T, K> & { [P in K]-?: T[P] }
4
5
  type VoidOrOptional<T> = [Exclude<T, undefined | void>] extends [never] ? void : Exclude<T, undefined | void>;
5
6
 
@@ -137,12 +138,12 @@ export interface DialogOptions<T, V = T | undefined> {
137
138
  /**
138
139
  * A callback that render dialog contents.
139
140
  */
140
- onRender: React.VFC<DialogContext<V> & this>;
141
+ onRender: VFC<DialogContext<V> & this>;
141
142
  /**
142
143
  * Specifies wrapper component that envelops content from {@link DialogOptions.onRender},
143
144
  * which is useful for reusable layout for dialogs.
144
145
  */
145
- wrapper?: React.FC<DialogContext<V> & this & React.PropsWithChildren<{}>>;
146
+ wrapper?: React.FC<DialogContext<V> & this & { children: React.ReactElement }>;
146
147
  /**
147
148
  * An optional signal object to dismiss the dialog.
148
149
  *
@@ -156,6 +157,10 @@ export interface DialogOptions<T, V = T | undefined> {
156
157
  }
157
158
 
158
159
  export interface DialogContext<V> {
160
+ /**
161
+ * Gets the root element of the dialog.
162
+ */
163
+ dialogElement: HTMLElement;
159
164
  /**
160
165
  * Gets an {@link ErrorHandler} object that catches errors emitted from rendered content.
161
166
  */
package/dialog.js CHANGED
@@ -30,9 +30,10 @@ function createDialogElement(props, unmountAfterUse) {
30
30
  (props.onOpen || noop)(root);
31
31
  },
32
32
  flyouthide: function () {
33
- removeNode(root);
34
33
  (props.onClose || noop)(root);
35
- (unmountAfterUse || noop)();
34
+ resolve(unmountAfterUse()).then(function () {
35
+ removeNode(root);
36
+ });
36
37
  }
37
38
  });
38
39
  root.setAttribute('loading-class', '');
@@ -83,6 +84,7 @@ export function createDialog(props) {
83
84
  return runAsync(dom.activeElement, props.onCommit.bind(this, value)).then(closeDialog);
84
85
  } : closeDialog;
85
86
  var dialogProps = extend({}, props, {
87
+ dialogElement: root,
86
88
  errorHandler: scope.errorHandler,
87
89
  closeDialog: commitDialog,
88
90
  commitDialog: commitDialog,
@@ -118,7 +120,9 @@ export function createDialog(props) {
118
120
  */
119
121
  export function createDialogQueue(props) {
120
122
  var mode = props && props.mode;
121
- var root = mode && createDialogElement(props);
123
+ var root = mode && createDialogElement(props, function () {
124
+ return multiple && closeFlyout(root.children);
125
+ });
122
126
  var multiple = mode === 'multiple';
123
127
  var childProps;
124
128
  var queue = [];
@@ -187,7 +191,7 @@ export function createDialogQueue(props) {
187
191
  export function Dialog(props) {
188
192
  const _props = extend(useState({})[0], props);
189
193
  const element = useState(function () {
190
- return createDialogElement(_props);
194
+ return createDialogElement(_props, noop);
191
195
  })[0];
192
196
  useEffect(function () {
193
197
  var opened = isFlyoutOpen(element);
@@ -1,4 +1,4 @@
1
- /*! brew-js-react v0.7.3 | (c) misonou | https://misonou.github.io */
1
+ /*! brew-js-react v0.7.4 | (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("brew-js"), require("react"), require("react-dom"), require("zeta-dom-react"), require("waterpipe"), require("jquery"));
@@ -248,6 +248,7 @@ var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_
248
248
  fill = _lib$util.fill,
249
249
  freeze = _lib$util.freeze,
250
250
  grep = _lib$util.grep,
251
+ util_hasOwnProperty = _lib$util.hasOwnProperty,
251
252
  isArray = _lib$util.isArray,
252
253
  isFunction = _lib$util.isFunction,
253
254
  isPlainObject = _lib$util.isPlainObject,
@@ -398,9 +399,10 @@ function createDialogElement(props, unmountAfterUse) {
398
399
  (props.onOpen || noop)(root);
399
400
  },
400
401
  flyouthide: function flyouthide() {
401
- removeNode(root);
402
402
  (props.onClose || noop)(root);
403
- (unmountAfterUse || noop)();
403
+ resolve(unmountAfterUse()).then(function () {
404
+ removeNode(root);
405
+ });
404
406
  }
405
407
  });
406
408
  root.setAttribute('loading-class', '');
@@ -448,6 +450,7 @@ function createDialog(props) {
448
450
  return runAsync(zeta_dom_dom.activeElement, props.onCommit.bind(this, value)).then(closeDialog);
449
451
  } : closeDialog;
450
452
  var dialogProps = extend({}, props, {
453
+ dialogElement: root,
451
454
  errorHandler: scope.errorHandler,
452
455
  closeDialog: commitDialog,
453
456
  commitDialog: commitDialog,
@@ -484,7 +487,9 @@ function createDialog(props) {
484
487
  */
485
488
  function createDialogQueue(props) {
486
489
  var mode = props && props.mode;
487
- var root = mode && createDialogElement(props);
490
+ var root = mode && createDialogElement(props, function () {
491
+ return multiple && closeFlyout(root.children);
492
+ });
488
493
  var multiple = mode === 'multiple';
489
494
  var childProps;
490
495
  var queue = [];
@@ -554,7 +559,7 @@ function createDialogQueue(props) {
554
559
  function Dialog(props) {
555
560
  var _props = extend(useState({})[0], props);
556
561
  var element = useState(function () {
557
- return createDialogElement(_props);
562
+ return createDialogElement(_props, noop);
558
563
  })[0];
559
564
  useEffect(function () {
560
565
  var opened = isFlyoutOpen(element);
@@ -625,9 +630,7 @@ onAppInit(function () {
625
630
  view_event = e;
626
631
  (function updateViewRecursive(next) {
627
632
  each(next.children, function (i, v) {
628
- e.waitFor(new Promise(function (resolve) {
629
- v.forceUpdate(resolve);
630
- }).then(function () {
633
+ e.waitFor(v.renderAsync().then(function () {
631
634
  updateViewRecursive(v);
632
635
  }));
633
636
  });
@@ -755,6 +758,7 @@ definePrototype(ErrorBoundary, Component, {
755
758
  function ViewContainer() {
756
759
  Component.apply(this, arguments);
757
760
  this.views = [];
761
+ this.dispose = new Set();
758
762
  }
759
763
  ViewContainer.contextType = StateContext;
760
764
  definePrototype(ViewContainer, Component, {
@@ -771,6 +775,7 @@ definePrototype(ViewContainer, Component, {
771
775
  setImmediate(function () {
772
776
  if (self.currentContext && !self.currentContext.active) {
773
777
  self.unmountView();
778
+ combineFn(self.dispose)();
774
779
  }
775
780
  });
776
781
  };
@@ -785,6 +790,16 @@ definePrototype(ViewContainer, Component, {
785
790
  this.currentContext = context;
786
791
  (this.props.rootProps.ref || {}).current = context;
787
792
  },
793
+ renderAsync: function renderAsync() {
794
+ var self = this;
795
+ return new Promise(function (resolve) {
796
+ self.dispose.add(resolve);
797
+ self.forceUpdate(function () {
798
+ self.dispose["delete"](resolve);
799
+ resolve();
800
+ });
801
+ });
802
+ },
788
803
  render: function render() {
789
804
  /** @type {any} */
790
805
  var self = this;
@@ -841,9 +856,7 @@ definePrototype(ViewContainer, Component, {
841
856
  }, true);
842
857
  return animateOut(element, 'show').then(function () {
843
858
  self.views[0] = null;
844
- return new Promise(function (resolve) {
845
- self.forceUpdate(resolve);
846
- });
859
+ return self.renderAsync();
847
860
  });
848
861
  });
849
862
  always(promise || delay(), function () {
@@ -891,33 +904,26 @@ function normalizePart(value, part) {
891
904
  function getCurrentParams(view, params) {
892
905
  var state = routeMap.get(view);
893
906
  if (!state.maxParams) {
894
- var matchers = exclude(state.matchers, ['remainingSegments']);
907
+ var maxParams = {};
895
908
  var matched = map(app_app.routes, function (v) {
896
909
  var route = app_app.parseRoute(v);
897
- var matched = route.length && !any(matchers, function (v, i) {
898
- var pos = route.params[i];
899
- return (v ? !(pos >= 0) : pos < route.minLength) || !isFunction(v) && !route.match(i, v);
910
+ var routeParams = route.params;
911
+ var params = {};
912
+ var invalid = single(routeParams, function (v, i) {
913
+ if (usedParams[i] && !state.matchers[i]) {
914
+ return v < route.minLength;
915
+ }
916
+ params[i] = true;
917
+ }) || single(state.matchers, function (v, i) {
918
+ return i !== 'remainingSegments' && !(isFunction(v) ? util_hasOwnProperty(routeParams, i) : v ? route.match(i, v) : routeParams[i] >= route.minLength);
900
919
  });
901
- return matched ? route : null;
920
+ return invalid ? null : extend(maxParams, params) && route;
921
+ });
922
+ var last = matched.slice(-1)[0] || {};
923
+ state.maxParams = ['remainingSegments'].concat(util_keys(maxParams));
924
+ state.minParams = map(last.params, function (v, i) {
925
+ return state.params[i] || v >= last.minLength ? null : i;
902
926
  });
903
- if (matched[1]) {
904
- matched = grep(matched, function (v) {
905
- return !single(v.params, function (v, i) {
906
- return usedParams[i] && !matchers[i];
907
- });
908
- });
909
- }
910
- if (matched[0]) {
911
- var last = matched.slice(-1)[0];
912
- state.maxParams = util_keys(extend.apply(0, [{
913
- remainingSegments: true
914
- }].concat(matched.map(function (v) {
915
- return v.params;
916
- }))));
917
- state.minParams = map(last.params, function (v, i) {
918
- return state.params[i] || v >= last.minLength ? null : i;
919
- });
920
- }
921
927
  }
922
928
  return extend(pick(app_app.route, state.minParams), params && pick(params, state.maxParams), state.params);
923
929
  }