brew-js-react 0.2.1 → 0.2.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,8 +1,9 @@
1
1
  import React, { useEffect, useState } from "react";
2
2
  import ReactDOM from "react-dom";
3
- import { always, either, extend, noop } from "./include/zeta-dom/util.js";
3
+ import { always, catchAsync, either, extend, noop, pipe, resolve } 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
7
  import { closeFlyout, openFlyout } from "./include/brew-js/domAction.js";
7
8
 
8
9
  /**
@@ -42,14 +43,19 @@ export function createDialog(props) {
42
43
  dom.setModal(root);
43
44
  }
44
45
  if (props.onRender) {
45
- ReactDOM.render(React.createElement(props.onRender, extend({ closeDialog }, props)), root);
46
+ var dialogProps = extend({}, props, {
47
+ closeDialog: function (value) {
48
+ var promise = resolve((props.onCommit || pipe)(value));
49
+ catchAsync(lock(dom.activeElement, promise));
50
+ promise.then(closeDialog);
51
+ }
52
+ });
53
+ ReactDOM.render(React.createElement(props.onRender, dialogProps), root);
46
54
  }
47
-
48
55
  promise = openFlyout(root);
49
56
  always(promise, function () {
50
57
  promise = null;
51
58
  });
52
- promise.then(props.onCommit);
53
59
  (props.onOpen || noop)(root);
54
60
  return promise;
55
61
  }
@@ -276,6 +276,7 @@ var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_
276
276
  watchOnce = _lib$util.watchOnce,
277
277
  watchable = _lib$util.watchable,
278
278
  inherit = _lib$util.inherit,
279
+ freeze = _lib$util.freeze,
279
280
  deepFreeze = _lib$util.deepFreeze,
280
281
  iequal = _lib$util.iequal,
281
282
  randomId = _lib$util.randomId,
@@ -363,6 +364,17 @@ var _lib$dom = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_z
363
364
 
364
365
 
365
366
  /* harmony default export */ const zeta_dom_dom = (dom);
367
+ ;// CONCATENATED MODULE: ./tmp/zeta-dom/domLock.js
368
+
369
+ var domLock_lib$dom = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_.dom,
370
+ lock = domLock_lib$dom.lock,
371
+ locked = domLock_lib$dom.locked,
372
+ cancelLock = domLock_lib$dom.cancelLock,
373
+ notifyAsync = domLock_lib$dom.notifyAsync,
374
+ preventLeave = domLock_lib$dom.preventLeave;
375
+
376
+ ;// CONCATENATED MODULE: ./src/include/zeta-dom/domLock.js
377
+
366
378
  ;// CONCATENATED MODULE: ./tmp/brew-js/domAction.js
367
379
 
368
380
  var addAsyncAction = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.addAsyncAction,
@@ -378,6 +390,7 @@ var addAsyncAction = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_roo
378
390
 
379
391
 
380
392
 
393
+
381
394
  /**
382
395
  * @param {Partial<import("./dialog").DialogOptions<any>>} props
383
396
  */
@@ -387,7 +400,7 @@ function createDialog(props) {
387
400
  var closing = false;
388
401
  var promise;
389
402
 
390
- function closeDialog(value) {
403
+ function _closeDialog(value) {
391
404
  if (!closing) {
392
405
  closing = true;
393
406
  closeFlyout(root, value).then(function () {
@@ -404,7 +417,7 @@ function createDialog(props) {
404
417
 
405
418
  return {
406
419
  root: root,
407
- close: closeDialog,
420
+ close: _closeDialog,
408
421
  open: function open() {
409
422
  if (promise) {
410
423
  return promise;
@@ -420,16 +433,20 @@ function createDialog(props) {
420
433
  }
421
434
 
422
435
  if (props.onRender) {
423
- external_commonjs_react_dom_commonjs2_react_dom_amd_react_dom_root_ReactDOM_.render( /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(props.onRender, extend({
424
- closeDialog: closeDialog
425
- }, props)), root);
436
+ var dialogProps = extend({}, props, {
437
+ closeDialog: function closeDialog(value) {
438
+ var promise = resolve((props.onCommit || pipe)(value));
439
+ catchAsync(lock(zeta_dom_dom.activeElement, promise));
440
+ promise.then(_closeDialog);
441
+ }
442
+ });
443
+ external_commonjs_react_dom_commonjs2_react_dom_amd_react_dom_root_ReactDOM_.render( /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(props.onRender, dialogProps), root);
426
444
  }
427
445
 
428
446
  promise = openFlyout(root);
429
447
  always(promise, function () {
430
448
  promise = null;
431
449
  });
432
- promise.then(props.onCommit);
433
450
  (props.onOpen || noop)(root);
434
451
  return promise;
435
452
  }
@@ -463,6 +480,12 @@ function Dialog(props) {
463
480
  }
464
481
  // EXTERNAL MODULE: external "zeta-dom-react"
465
482
  var external_zeta_dom_react_ = __webpack_require__(103);
483
+ ;// CONCATENATED MODULE: ./tmp/zeta-dom/events.js
484
+
485
+ var ZetaEventContainer = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_.EventContainer;
486
+
487
+ ;// CONCATENATED MODULE: ./src/include/zeta-dom/events.js
488
+
466
489
  ;// CONCATENATED MODULE: ./tmp/brew-js/defaults.js
467
490
 
468
491
  var defaults_defaultExport = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.defaults;
@@ -481,17 +504,6 @@ install('react', function (app_) {
481
504
  app_app = app_;
482
505
  });
483
506
  brew_js_defaults.react = true;
484
- ;// CONCATENATED MODULE: ./tmp/zeta-dom/domLock.js
485
-
486
- var domLock_lib$dom = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_.dom,
487
- lock = domLock_lib$dom.lock,
488
- locked = domLock_lib$dom.locked,
489
- cancelLock = domLock_lib$dom.cancelLock,
490
- notifyAsync = domLock_lib$dom.notifyAsync,
491
- preventLeave = domLock_lib$dom.preventLeave;
492
-
493
- ;// CONCATENATED MODULE: ./src/include/zeta-dom/domLock.js
494
-
495
507
  ;// CONCATENATED MODULE: ./tmp/brew-js/anim.js
496
508
 
497
509
  var animateIn = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.animateIn,
@@ -560,11 +572,14 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
560
572
  self.currentViewComponent = V;
561
573
 
562
574
  if (self.currentView && self.currentElement) {
575
+ var prevPath = self.currentPath;
576
+ var prevElement = self.currentElement;
563
577
  self.prevView = self.currentView;
564
- self.prevElement = self.currentElement;
565
578
  self.currentElement = undefined;
566
- animateOut(self.prevElement, 'show').then(function () {
567
- self.prevElement = undefined;
579
+ app_app.emit('pageleave', prevElement, {
580
+ pathname: prevPath
581
+ }, true);
582
+ animateOut(prevElement, 'show').then(function () {
568
583
  self.prevView = undefined;
569
584
  self.forceUpdate();
570
585
  });
@@ -581,15 +596,22 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
581
596
  self.parentElement = element.parentElement;
582
597
  util_setImmediate(function () {
583
598
  resolve();
584
- return animateIn(element, 'show');
599
+ animateIn(element, 'show');
600
+ app_app.emit('pageenter', element, {
601
+ pathname: app_app.path
602
+ }, true);
585
603
  });
586
604
  }
587
605
  })));
588
606
  defineGetterProperty(providerProps.value, 'active', function () {
589
607
  return self.currentView === view;
590
608
  });
609
+ self.currentPath = app_app.path;
591
610
  self.currentView = view;
592
611
  } else {
612
+ app_app.emit('pageenter', self.currentElement, {
613
+ pathname: app_app.path
614
+ }, true);
593
615
  resolve();
594
616
  }
595
617
 
@@ -685,12 +707,32 @@ function redirectTo(view, params) {
685
707
 
686
708
 
687
709
 
710
+
711
+ var emitter = new ZetaEventContainer();
688
712
  var states = {};
689
713
 
690
714
  function getCurrentStates() {
691
715
  return states[history.state] || (states[history.state] = {});
692
716
  }
693
717
 
718
+ function ViewState(value) {
719
+ this.value = value;
720
+ }
721
+
722
+ definePrototype(ViewState, {
723
+ get: function get() {
724
+ return this.value;
725
+ },
726
+ set: function set(value) {
727
+ this.value = value;
728
+ },
729
+ onPopState: function onPopState(callback) {
730
+ throwNotFunction(callback);
731
+ return emitter.add(this, 'popstate', function (e) {
732
+ callback.call(this, e.newValue);
733
+ });
734
+ }
735
+ });
694
736
  function useAppReady() {
695
737
  var sReady = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(false);
696
738
  var ready = sReady[0],
@@ -705,32 +747,37 @@ function useAppReady() {
705
747
  function useRouteParam(name, defaultValue) {
706
748
  var container = useViewContainerState();
707
749
  var route = app_app.route;
708
- var sValue = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(route[name]);
709
- var value = sValue[0],
710
- setValue = sValue[1];
750
+ var value = route[name] || '';
751
+ var ref = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useRef)(value);
752
+ var forceUpdate = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)()[1];
711
753
  (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect)(function () {
712
- var current = route[name]; // route parameter might be changed after state initialization and before useEffect hook is called
754
+ var setValue = function setValue() {
755
+ var current = route[name] || '';
756
+
757
+ if (container.active && current !== ref.current) {
758
+ ref.current = current;
759
+ forceUpdate({});
760
+ }
761
+ }; // route parameter might be changed after state initialization and before useEffect hook is called
762
+
713
763
 
714
- setValue(current);
764
+ setValue();
715
765
 
716
766
  if (name in route) {
717
- return route.watch(name, function (value) {
718
- util_setImmediate(function () {
719
- if (container.active) {
720
- setValue(value);
721
- }
722
- });
767
+ return route.watch(name, function () {
768
+ setImmediateOnce(setValue);
723
769
  });
724
770
  }
725
771
 
726
772
  console.error('Route parameter ' + name + ' does not exist');
727
773
  }, [name, defaultValue]);
774
+ ref.current = value;
728
775
 
729
776
  if (!value && defaultValue !== undefined) {
730
777
  app_app.navigate(route.getPath(extend({}, route, kv(name, defaultValue))), true);
731
778
  }
732
779
 
733
- return value || '';
780
+ return value;
734
781
  }
735
782
  function useRouteState(key, defaultValue) {
736
783
  var container = useViewContainerState();
@@ -750,17 +797,23 @@ function ViewStateContainer(props) {
750
797
  return {
751
798
  getState: function getState(uniqueId, key) {
752
799
  var cur = getCurrentStates();
753
- var state = cache[uniqueId] || (cache[uniqueId] = {
754
- value: cur[key] && cur[key].value,
755
- get: function get() {
756
- return state.value;
757
- },
758
- set: function set(value) {
759
- state.value = value;
760
- }
761
- });
800
+ var state = cache[uniqueId] || (cache[uniqueId] = new ViewState(cur[key] && cur[key].value));
762
801
 
763
802
  if (container.active) {
803
+ var stateId = state.stateId;
804
+
805
+ if (stateId && stateId !== history.state) {
806
+ var newValue = cur[key] && cur[key].value;
807
+ emitter.emit('popstate', state, {
808
+ newValue: newValue
809
+ }); // detach value in previous history state from current one
810
+
811
+ var previous = new ViewState(state.value);
812
+ states[stateId][key] = previous;
813
+ state.value = newValue;
814
+ }
815
+
816
+ state.stateId = history.state;
764
817
  cur[key] = state;
765
818
  }
766
819
 
@@ -895,7 +948,8 @@ definePrototype(Mixin, {
895
948
  },
896
949
  getCustomAttributes: function getCustomAttributes() {
897
950
  return {};
898
- }
951
+ },
952
+ dispose: function dispose() {}
899
953
  });
900
954
  watchable(Mixin.prototype);
901
955
  util_define(Mixin, {
@@ -1023,6 +1077,13 @@ definePrototype(StatefulMixin, Mixin, {
1023
1077
  });
1024
1078
 
1025
1079
  return clone;
1080
+ },
1081
+ dispose: function dispose() {
1082
+ var states = _(this).states;
1083
+
1084
+ each(states, function (i, v) {
1085
+ delete states[i];
1086
+ });
1026
1087
  }
1027
1088
  });
1028
1089
  ;// CONCATENATED MODULE: ./src/mixins/ClassNameMixin.js
@@ -1162,19 +1223,13 @@ definePrototype(AnimateSequenceMixin, AnimateMixin, {
1162
1223
  });
1163
1224
  }
1164
1225
  });
1165
- ;// CONCATENATED MODULE: ./tmp/zeta-dom/events.js
1166
-
1167
- var ZetaEventContainer = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_zeta_.EventContainer;
1168
-
1169
- ;// CONCATENATED MODULE: ./src/include/zeta-dom/events.js
1170
-
1171
1226
  ;// CONCATENATED MODULE: ./src/mixins/ErrorHandlerMixin.js
1172
1227
 
1173
1228
 
1174
1229
 
1175
1230
 
1176
1231
  var ErrorHandlerMixinSuper = StatefulMixin.prototype;
1177
- var emitter = new ZetaEventContainer();
1232
+ var ErrorHandlerMixin_emitter = new ZetaEventContainer();
1178
1233
 
1179
1234
  function isErrorMatched(filter, error) {
1180
1235
  if (isFunction(filter)) {
@@ -1194,7 +1249,7 @@ definePrototype(ErrorHandlerMixin, StatefulMixin, {
1194
1249
  filter = null;
1195
1250
  }
1196
1251
 
1197
- return emitter.add(this, filter ? 'error' : 'default', function (e) {
1252
+ return ErrorHandlerMixin_emitter.add(this, filter ? 'error' : 'default', function (e) {
1198
1253
  if (!filter || isErrorMatched(filter, e.error)) {
1199
1254
  return callback(e.error);
1200
1255
  }
@@ -1207,7 +1262,7 @@ definePrototype(ErrorHandlerMixin, StatefulMixin, {
1207
1262
  var data = {
1208
1263
  error: e.error
1209
1264
  };
1210
- return emitter.emit('error', self, data) || emitter.emit('default', self, data);
1265
+ return ErrorHandlerMixin_emitter.emit('error', self, data) || ErrorHandlerMixin_emitter.emit('default', self, data);
1211
1266
  });
1212
1267
  }
1213
1268
  });
@@ -1243,6 +1298,7 @@ function FlyoutMixin() {
1243
1298
  var self = this;
1244
1299
  ClassNameMixin.call(self, ['open', 'closing', 'tweening-in', 'tweening-out']);
1245
1300
  self.modal = false;
1301
+ self.tabThrough = false;
1246
1302
  self.isFlyoutOpened = false;
1247
1303
  self.animating = false;
1248
1304
  self.visible = false;
@@ -1268,6 +1324,8 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1268
1324
  'swipe-dismiss': self.swipeToDismiss
1269
1325
  }, self.modal && {
1270
1326
  'is-modal': ''
1327
+ }, self.tabThrough && {
1328
+ 'tab-through': ''
1271
1329
  }, self.effects && {
1272
1330
  'animate-on': 'open',
1273
1331
  'animate-in': self.effects.join(' '),
@@ -1337,9 +1395,9 @@ definePrototype(FocusStateMixin, StatefulMixin, {
1337
1395
  initElement: function initElement(element, state) {
1338
1396
  FocusStateMixinSuper.initElement.call(this, element, state);
1339
1397
  zeta_dom_dom.on(element, {
1340
- focusin: function focusin() {
1398
+ focusin: function focusin(e) {
1341
1399
  state.focused = true;
1342
- setClass(element, 'focused', true);
1400
+ setClass(element, 'focused', e.source);
1343
1401
  },
1344
1402
  focusout: function focusout() {
1345
1403
  state.focused = false;
@@ -1487,9 +1545,13 @@ var useFocusStateMixin = createUseFunction(FocusStateMixin);
1487
1545
  var useLoadingStateMixin = createUseFunction(LoadingStateMixin);
1488
1546
  var useScrollableMixin = createUseFunction(ScrollableMixin);
1489
1547
  function useMixin(ctor) {
1490
- return (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(function () {
1548
+ var mixin = (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useState)(function () {
1491
1549
  return new ctor();
1492
1550
  })[0].reset();
1551
+ (0,external_commonjs_react_commonjs2_react_amd_react_root_React_.useEffect)(function () {
1552
+ return mixin.dispose.bind(mixin);
1553
+ }, []);
1554
+ return mixin;
1493
1555
  }
1494
1556
  function useMixinRef(mixin) {
1495
1557
  return mixin && mixin.getMixin().reset();