brew-js-react 0.2.4 → 0.2.7

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.
@@ -210,7 +210,8 @@ var _defaultExport = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_roo
210
210
  /* harmony default export */ const app = (_defaultExport);
211
211
  var install = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.install,
212
212
  addExtension = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.addExtension,
213
- addDetect = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.addDetect;
213
+ addDetect = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.addDetect,
214
+ isElementActive = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.isElementActive;
214
215
 
215
216
  ;// CONCATENATED MODULE: ./src/include/brew-js/app.js
216
217
 
@@ -244,8 +245,10 @@ var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_
244
245
  any = _lib$util.any,
245
246
  single = _lib$util.single,
246
247
  kv = _lib$util.kv,
248
+ fill = _lib$util.fill,
247
249
  pick = _lib$util.pick,
248
250
  exclude = _lib$util.exclude,
251
+ mapObject = _lib$util.mapObject,
249
252
  mapGet = _lib$util.mapGet,
250
253
  mapRemove = _lib$util.mapRemove,
251
254
  arrRemove = _lib$util.arrRemove,
@@ -262,6 +265,7 @@ var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_
262
265
  setImmediateOnce = _lib$util.setImmediateOnce,
263
266
  throwNotFunction = _lib$util.throwNotFunction,
264
267
  errorWithCode = _lib$util.errorWithCode,
268
+ isErrorWithCode = _lib$util.isErrorWithCode,
265
269
  util_keys = _lib$util.keys,
266
270
  values = _lib$util.values,
267
271
  util_hasOwnProperty = _lib$util.hasOwnProperty,
@@ -293,8 +297,12 @@ var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_
293
297
  reject = _lib$util.reject,
294
298
  always = _lib$util.always,
295
299
  resolveAll = _lib$util.resolveAll,
300
+ retryable = _lib$util.retryable,
301
+ deferrable = _lib$util.deferrable,
296
302
  catchAsync = _lib$util.catchAsync,
297
- setPromiseTimeout = _lib$util.setPromiseTimeout;
303
+ setPromiseTimeout = _lib$util.setPromiseTimeout,
304
+ delay = _lib$util.delay,
305
+ makeAsync = _lib$util.makeAsync;
298
306
 
299
307
  ;// CONCATENATED MODULE: ./src/include/zeta-dom/util.js
300
308
 
@@ -514,6 +522,20 @@ var animateIn = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_bre
514
522
 
515
523
  ;// CONCATENATED MODULE: ./src/include/brew-js/anim.js
516
524
 
525
+ ;// CONCATENATED MODULE: ./tmp/brew-js/util/path.js
526
+
527
+ var setBaseUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.setBaseUrl,
528
+ combinePath = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.combinePath,
529
+ normalizePath = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.normalizePath,
530
+ removeQueryAndHash = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.removeQueryAndHash,
531
+ withBaseUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.withBaseUrl,
532
+ toAbsoluteUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.toAbsoluteUrl,
533
+ toRelativeUrl = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.toRelativeUrl,
534
+ isSubPathOf = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.isSubPathOf,
535
+ toSegments = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_brew_.toSegments;
536
+
537
+ ;// CONCATENATED MODULE: ./src/include/brew-js/util/path.js
538
+
517
539
  ;// CONCATENATED MODULE: ./src/view.js
518
540
 
519
541
 
@@ -523,6 +545,7 @@ var animateIn = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_bre
523
545
 
524
546
 
525
547
 
548
+
526
549
  var view_root = zeta_dom_dom.root;
527
550
  var routeMap = new Map();
528
551
  var usedParams = {};
@@ -530,32 +553,23 @@ var sortedViews = [];
530
553
  var StateContext = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createContext(Object.freeze({
531
554
  active: true
532
555
  }));
533
- var stateId;
534
556
 
535
557
  function ViewContainer() {
536
- /** @type {any} */
537
- var self = this;
538
- external_commonjs_react_commonjs2_react_amd_react_root_React_.Component.apply(self, arguments);
539
- self.mounted = false;
540
-
541
- if (!stateId) {
542
- stateId = history.state;
543
- app_app.on('navigate', function () {
544
- stateId = history.state;
545
- });
546
- }
547
-
548
- self.componentWillUnmount = app_app.on('navigate', function () {
549
- if (self.mounted && self.getViewComponent()) {
550
- self.isForceUpdate = true;
551
- self.forceUpdate();
552
- }
553
- });
558
+ external_commonjs_react_commonjs2_react_amd_react_root_React_.Component.apply(this, arguments);
559
+ this.stateId = history.state;
554
560
  }
555
561
 
556
562
  definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react_root_React_.Component, {
557
563
  componentDidMount: function componentDidMount() {
558
- this.mounted = true;
564
+ /** @type {any} */
565
+ var self = this;
566
+ self.componentWillUnmount = combineFn(watch(app_app.route, function () {
567
+ self.setActive(self.getViewComponent() === self.currentViewComponent);
568
+ }), app_app.on('beforepageload', function (e) {
569
+ self.waitFor = e.waitFor;
570
+ self.stateId = history.state;
571
+ self.forceUpdate();
572
+ }));
559
573
  },
560
574
  componentDidCatch: function componentDidCatch(error) {
561
575
  zeta_dom_dom.emit('error', this.parentElement || view_root, {
@@ -565,22 +579,32 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
565
579
  render: function render() {
566
580
  /** @type {any} */
567
581
  var self = this;
568
- var resolve;
569
- var promise = new Promise(function (_resolve) {
570
- resolve = _resolve;
571
- });
582
+
583
+ if (history.state !== self.stateId) {
584
+ return self.lastChild || null;
585
+ }
586
+
572
587
  var V = self.getViewComponent();
573
588
 
589
+ if (V) {
590
+ // ensure the current path actually corresponds to the matched view
591
+ // when some views are not included in the list of allowed views
592
+ var targetPath = linkTo(V, getCurrentParams(V, true));
593
+
594
+ if (targetPath !== removeQueryAndHash(app_app.path)) {
595
+ app_app.navigate(targetPath, true);
596
+ }
597
+ }
598
+
574
599
  if (V && V !== self.currentViewComponent) {
575
- self.currentViewComponent = V;
600
+ var prevElement = self.currentElement;
576
601
 
577
- if (self.currentView && self.currentElement) {
578
- var prevPath = self.currentPath;
579
- var prevElement = self.currentElement;
602
+ if (prevElement) {
603
+ self.setActive(false);
580
604
  self.prevView = self.currentView;
581
605
  self.currentElement = undefined;
582
606
  app_app.emit('pageleave', prevElement, {
583
- pathname: prevPath
607
+ pathname: self.currentPath
584
608
  }, true);
585
609
  animateOut(prevElement, 'show').then(function () {
586
610
  self.prevView = undefined;
@@ -588,15 +612,19 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
588
612
  });
589
613
  }
590
614
 
591
- var providerProps = {
592
- key: routeMap.get(V).id,
593
- value: {
594
- view: V
595
- }
615
+ var resolve;
616
+ var promise = new Promise(function (resolve_) {
617
+ resolve = resolve_;
618
+ });
619
+ var state = {
620
+ view: V
596
621
  };
597
- var view = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(StateContext.Provider, providerProps, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ViewStateContainer, null, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(V, {
622
+ var view = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(StateContext.Provider, {
623
+ key: routeMap.get(V).id,
624
+ value: state
625
+ }, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ViewStateContainer, null, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(V, {
598
626
  rootProps: self.props.rootProps,
599
- onComponentLoaded: function onComponentLoaded(element) {
627
+ onComponentLoaded: executeOnce(function (element) {
600
628
  self.currentElement = element;
601
629
  self.parentElement = element.parentElement;
602
630
  util_setImmediate(function () {
@@ -606,42 +634,25 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
606
634
  pathname: app_app.path
607
635
  }, true);
608
636
  });
609
- }
637
+ })
610
638
  })));
611
- defineGetterProperty(providerProps.value, 'active', function () {
612
- return self.currentView === view;
639
+ extend(self, {
640
+ currentPath: app_app.path,
641
+ currentView: view,
642
+ currentViewComponent: V,
643
+ setActive: defineObservableProperty(state, 'active', true, true)
613
644
  });
614
- self.currentPath = app_app.path;
615
- self.currentView = view;
616
- } else {
617
- if (self.isForceUpdate) {
618
- self.isForceUpdate = false;
619
- app_app.emit('pageenter', self.currentElement, {
620
- pathname: app_app.path
621
- }, true);
622
- }
623
-
624
- resolve();
645
+ (self.waitFor || noop)(promise);
646
+ notifyAsync(self.parentElement || view_root, promise);
625
647
  }
626
648
 
627
- notifyAsync(self.parentElement || view_root, promise);
628
- return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(external_commonjs_react_commonjs2_react_amd_react_root_React_.Fragment, null, self.prevView, self.currentView);
649
+ var child = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(external_commonjs_react_commonjs2_react_amd_react_root_React_.Fragment, null, self.prevView, self.currentView);
650
+ self.lastChild = child;
651
+ return child;
629
652
  },
630
653
  getViewComponent: function getViewComponent() {
631
654
  var props = this.props;
632
- var matched = any(props.views, isViewMatched) || props.defaultView;
633
-
634
- if (history.state === stateId) {
635
- // ensure the current path actually corresponds to the matched view
636
- // when some views are not included in the list of allowed views
637
- var targetPath = linkTo(matched, getCurrentParams(matched, true));
638
-
639
- if (targetPath !== app_app.path) {
640
- app_app.navigate(targetPath, true);
641
- }
642
- }
643
-
644
- return matched;
655
+ return any(props.views, isViewMatched) || props.defaultView;
645
656
  }
646
657
  });
647
658
 
@@ -723,7 +734,7 @@ function registerView(factory, routeParams) {
723
734
  }
724
735
 
725
736
  return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement('div', extend({}, props.rootProps, {
726
- ref: ref,
737
+ ref: (0,external_zeta_dom_react_.combineRef)(ref, state[1].elementRef),
727
738
  children: state[0] && /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(state[0]["default"])
728
739
  }));
729
740
  };
@@ -789,7 +800,8 @@ function getCurrentStates() {
789
800
  return states[history.state] || (states[history.state] = {});
790
801
  }
791
802
 
792
- function ViewState(value) {
803
+ function ViewState(key, value) {
804
+ this.key = key;
793
805
  this.value = value;
794
806
  }
795
807
 
@@ -828,9 +840,13 @@ function useRouteParam(name, defaultValue) {
828
840
  var setValue = function setValue() {
829
841
  var current = route[name] || '';
830
842
 
831
- if (container.active && current !== ref.current) {
832
- ref.current = current;
833
- forceUpdate({});
843
+ if (current !== ref.current) {
844
+ if (container.active) {
845
+ ref.current = current;
846
+ forceUpdate({});
847
+ } else {
848
+ watch(container, 'active', setValue);
849
+ }
834
850
  }
835
851
  }; // route parameter might be changed after state initialization and before useEffect hook is called
836
852
 
@@ -871,20 +887,21 @@ function ViewStateContainer(props) {
871
887
  return {
872
888
  getState: function getState(uniqueId, key) {
873
889
  var cur = getCurrentStates();
874
- var state = cache[uniqueId] || (cache[uniqueId] = new ViewState(cur[key] && cur[key].value));
890
+ var state = cache[uniqueId] || (cache[uniqueId] = new ViewState(key, cur[key] && cur[key].value));
875
891
 
876
892
  if (container.active) {
877
893
  var stateId = state.stateId;
878
894
 
879
- if (stateId && stateId !== history.state) {
895
+ if (stateId && (stateId !== history.state || key !== state.key)) {
880
896
  var newValue = cur[key] && cur[key].value;
881
897
  emitter.emit('popstate', state, {
882
898
  newValue: newValue
883
899
  }); // detach value in previous history state from current one
884
900
 
885
- var previous = new ViewState(state.value);
886
- states[stateId][key] = previous;
901
+ var previous = new ViewState(state.key, state.value);
902
+ states[stateId][previous.key] = previous;
887
903
  state.value = newValue;
904
+ state.key = key;
888
905
  }
889
906
 
890
907
  state.stateId = history.state;
@@ -1093,6 +1110,7 @@ function StatefulMixin() {
1093
1110
  Mixin.call(this);
1094
1111
 
1095
1112
  _(this, {
1113
+ elements: new WeakSet(),
1096
1114
  states: {},
1097
1115
  prefix: '',
1098
1116
  counter: 0
@@ -1125,8 +1143,9 @@ definePrototype(StatefulMixin, Mixin, {
1125
1143
  var self = this;
1126
1144
  var state = self.state;
1127
1145
  return function (current) {
1128
- if (current && current !== state.element) {
1129
- state.element = current;
1146
+ state.element = current;
1147
+
1148
+ if (current && setAdd(_(self).elements, current)) {
1130
1149
  self.initElement(current, state);
1131
1150
  }
1132
1151
  };
@@ -1148,11 +1167,10 @@ definePrototype(StatefulMixin, Mixin, {
1148
1167
  var self = this;
1149
1168
  var clone = inherit(Object.getPrototypeOf(self), self);
1150
1169
 
1151
- _(clone, {
1152
- states: _(self).states,
1170
+ _(clone, extend({}, _(self), {
1153
1171
  prefix: randomId() + '.',
1154
1172
  counter: 0
1155
- });
1173
+ }));
1156
1174
 
1157
1175
  return clone;
1158
1176
  },
@@ -1339,18 +1357,6 @@ definePrototype(ErrorHandlerMixin, StatefulMixin, {
1339
1357
  });
1340
1358
  }
1341
1359
  });
1342
- ;// CONCATENATED MODULE: ./tmp/brew-js/var.js
1343
-
1344
- var getVarScope = undefined.getVarScope,
1345
- setVar = undefined.setVar,
1346
- declareVar = undefined.declareVar,
1347
- resetVar = undefined.resetVar,
1348
- getVar = undefined.getVar,
1349
- evaluate = undefined.evaluate,
1350
- evalAttr = undefined.evalAttr;
1351
-
1352
- ;// CONCATENATED MODULE: ./src/include/brew-js/var.js
1353
-
1354
1360
  ;// CONCATENATED MODULE: ./src/mixins/FlyoutToggleMixin.js
1355
1361
 
1356
1362
 
@@ -1379,9 +1385,8 @@ definePrototype(FlyoutToggleMixin, ClassNameMixin, {
1379
1385
 
1380
1386
 
1381
1387
 
1382
-
1383
1388
  var FlyoutMixinSuper = ClassNameMixin.prototype;
1384
- var varname = '__flyout' + randomId();
1389
+ var valueMap = new WeakMap();
1385
1390
  var flyoutMixinCounter = 0;
1386
1391
  function FlyoutMixin() {
1387
1392
  var self = this;
@@ -1422,7 +1427,9 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1422
1427
  });
1423
1428
  },
1424
1429
  open: function open(value) {
1425
- return openFlyout(this.elements()[0], kv(varname, value));
1430
+ var element = this.elements()[0];
1431
+ valueMap.set(element, value);
1432
+ return openFlyout(element);
1426
1433
  },
1427
1434
  close: function close(value) {
1428
1435
  return closeFlyout(this.elements()[0], value);
@@ -1431,7 +1438,7 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1431
1438
  var element = this.elements()[0];
1432
1439
  return this.onToggleState(function (opened) {
1433
1440
  if (opened) {
1434
- return callback(getVar(element, varname));
1441
+ return callback(valueMap.get(element));
1435
1442
  }
1436
1443
  });
1437
1444
  },
@@ -1447,7 +1454,6 @@ definePrototype(FlyoutMixin, ClassNameMixin, {
1447
1454
 
1448
1455
  if (!element.id) {
1449
1456
  element.id = 'flyout-' + ++flyoutMixinCounter;
1450
- declareVar(element, varname, undefined);
1451
1457
  }
1452
1458
 
1453
1459
  app_app.on(element, {