brew-js-react 0.6.6 → 0.6.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.
- package/dialog.d.ts +58 -1
- package/dialog.js +157 -58
- package/dist/brew-js-react.js +173 -73
- package/dist/brew-js-react.js.map +1 -1
- package/dist/brew-js-react.min.js +2 -2
- package/dist/brew-js-react.min.js.map +1 -1
- package/mixin.d.ts +13 -0
- package/mixin.js +8 -8
- package/package.json +1 -1
package/dist/brew-js-react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! brew-js-react v0.6.
|
|
1
|
+
/*! brew-js-react v0.6.7 | (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"));
|
|
@@ -180,10 +180,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
180
180
|
ScrollIntoViewMixin: () => (/* reexport */ ScrollIntoViewMixin),
|
|
181
181
|
ScrollableMixin: () => (/* reexport */ ScrollableMixin),
|
|
182
182
|
StatefulMixin: () => (/* reexport */ StatefulMixin),
|
|
183
|
+
StaticAttributeMixin: () => (/* reexport */ StaticAttributeMixin),
|
|
183
184
|
UnmanagedClassNameMixin: () => (/* reexport */ UnmanagedClassNameMixin),
|
|
184
185
|
ViewContext: () => (/* reexport */ ViewContext),
|
|
185
186
|
ViewStateContainer: () => (/* reexport */ ViewStateContainer),
|
|
186
187
|
createDialog: () => (/* reexport */ createDialog),
|
|
188
|
+
createDialogQueue: () => (/* reexport */ createDialogQueue),
|
|
187
189
|
isViewMatched: () => (/* reexport */ isViewMatched),
|
|
188
190
|
isViewRendered: () => (/* reexport */ isViewRendered),
|
|
189
191
|
linkTo: () => (/* reexport */ linkTo),
|
|
@@ -371,96 +373,195 @@ var closeFlyout = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_b
|
|
|
371
373
|
|
|
372
374
|
|
|
373
375
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
* @param {Partial<import("./dialog").DialogOptions<any>>} props
|
|
377
|
-
*/
|
|
378
|
-
function createDialog(props) {
|
|
379
|
-
var root = document.createElement('div');
|
|
380
|
-
var reactRoot = fallback.createRoot(root);
|
|
381
|
-
var scope = createAsyncScope(root);
|
|
382
|
-
var closeDialog = closeFlyout.bind(0, root);
|
|
376
|
+
var _ = createPrivateStore();
|
|
377
|
+
function debounceAsync(callback) {
|
|
383
378
|
var promise;
|
|
379
|
+
return function () {
|
|
380
|
+
if (!promise) {
|
|
381
|
+
promise = callback.apply(this, arguments);
|
|
382
|
+
always(promise, function () {
|
|
383
|
+
promise = null;
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
return promise;
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
function createDialogElement(props, unmountAfterUse) {
|
|
390
|
+
var root = document.createElement('div');
|
|
384
391
|
zeta_dom_dom.on(root, {
|
|
385
392
|
flyoutshow: function flyoutshow() {
|
|
386
393
|
(props.onOpen || noop)(root);
|
|
387
394
|
},
|
|
388
395
|
flyouthide: function flyouthide() {
|
|
389
|
-
promise = null;
|
|
390
396
|
removeNode(root);
|
|
391
397
|
(props.onClose || noop)(root);
|
|
392
|
-
|
|
393
|
-
reactRoot.unmount();
|
|
394
|
-
}
|
|
398
|
+
(unmountAfterUse || noop)();
|
|
395
399
|
}
|
|
396
400
|
});
|
|
397
401
|
root.setAttribute('loading-class', '');
|
|
398
402
|
subscribeAsync(root, true);
|
|
403
|
+
return root;
|
|
404
|
+
}
|
|
405
|
+
function openDialog(element, props, container) {
|
|
406
|
+
if (!containsOrEquals(zeta_dom_dom.root, element)) {
|
|
407
|
+
element.className = props.className || '';
|
|
408
|
+
(container || props.container || document.body).appendChild(element);
|
|
409
|
+
if (props.modal) {
|
|
410
|
+
element.setAttribute('is-modal', '');
|
|
411
|
+
}
|
|
412
|
+
setImmediate(function () {
|
|
413
|
+
zeta_dom_dom.retainFocus(zeta_dom_dom.activeElement, element);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
var promise = openFlyout(element, null, pick(props, ['focus', 'closeOnBlur']));
|
|
417
|
+
if (props.preventLeave) {
|
|
418
|
+
preventLeave(element, promise);
|
|
419
|
+
} else if (props.preventNavigation) {
|
|
420
|
+
lock(element, promise);
|
|
421
|
+
}
|
|
422
|
+
return promise;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* @param {Partial<import("./dialog").DialogOptions<any>>} props
|
|
427
|
+
*/
|
|
428
|
+
function createDialog(props) {
|
|
429
|
+
var controller = _(props.controller) || {};
|
|
430
|
+
var shared = controller.mode === 'shared';
|
|
431
|
+
var state = shared ? controller : {};
|
|
432
|
+
var root = state.root || (state.root = createDialogElement(props, function () {
|
|
433
|
+
reactRoot.unmount();
|
|
434
|
+
}));
|
|
435
|
+
var reactRoot = state.reactRoot || (state.reactRoot = fallback.createRoot(root));
|
|
436
|
+
var scope = state.scope || (state.scope = createAsyncScope(root));
|
|
437
|
+
var closeDialog = shared ? noop : closeFlyout.bind(0, root);
|
|
438
|
+
function render(closeDialog, props, container) {
|
|
439
|
+
var commitDialog = props.onCommit ? function (value) {
|
|
440
|
+
return runAsync(zeta_dom_dom.activeElement, props.onCommit.bind(this, value)).then(closeDialog);
|
|
441
|
+
} : closeDialog;
|
|
442
|
+
var dialogProps = extend({}, props, {
|
|
443
|
+
errorHandler: scope.errorHandler,
|
|
444
|
+
closeDialog: commitDialog,
|
|
445
|
+
commitDialog: commitDialog,
|
|
446
|
+
dismissDialog: closeDialog
|
|
447
|
+
});
|
|
448
|
+
var content = /*#__PURE__*/createElement(props.onRender, dialogProps);
|
|
449
|
+
if (props.wrapper) {
|
|
450
|
+
content = /*#__PURE__*/createElement(props.wrapper, dialogProps, content);
|
|
451
|
+
}
|
|
452
|
+
reactRoot.render( /*#__PURE__*/createElement(StrictMode, null, /*#__PURE__*/createElement(scope.Provider, null, content)));
|
|
453
|
+
return shared ? {
|
|
454
|
+
then: noop
|
|
455
|
+
} : openDialog(root, props, container);
|
|
456
|
+
}
|
|
399
457
|
return {
|
|
400
458
|
root: root,
|
|
401
|
-
close:
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
root.setAttribute('is-modal', '');
|
|
410
|
-
}
|
|
411
|
-
if (props.onRender) {
|
|
412
|
-
var commitDialog = props.onCommit ? function (value) {
|
|
413
|
-
return runAsync(zeta_dom_dom.activeElement, props.onCommit.bind(this, value)).then(closeDialog);
|
|
414
|
-
} : closeDialog;
|
|
415
|
-
var dialogProps = extend({}, props, {
|
|
416
|
-
errorHandler: scope.errorHandler,
|
|
417
|
-
closeDialog: commitDialog,
|
|
418
|
-
commitDialog: commitDialog,
|
|
419
|
-
dismissDialog: closeDialog
|
|
459
|
+
close: function close(value) {
|
|
460
|
+
return closeDialog(value);
|
|
461
|
+
},
|
|
462
|
+
open: debounceAsync(function () {
|
|
463
|
+
if (controller.enqueue) {
|
|
464
|
+
return controller.enqueue(function (next) {
|
|
465
|
+
closeDialog = shared ? next : closeDialog;
|
|
466
|
+
render(closeDialog, extend({}, controller.props, props), controller.root).then(next);
|
|
420
467
|
});
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
468
|
+
}
|
|
469
|
+
return render(closeDialog, props);
|
|
470
|
+
})
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* @param {import("./dialog").DialogControllerOptions | undefined} props
|
|
476
|
+
*/
|
|
477
|
+
function createDialogQueue(props) {
|
|
478
|
+
var mode = props && props.mode;
|
|
479
|
+
var root = mode && createDialogElement(props);
|
|
480
|
+
var multiple = mode === 'multiple';
|
|
481
|
+
var childProps;
|
|
482
|
+
var queue = [];
|
|
483
|
+
var active = [];
|
|
484
|
+
var controller = {};
|
|
485
|
+
var setPendingCount = defineObservableProperty(controller, 'pendingCount', 0, true);
|
|
486
|
+
function dismissPending() {
|
|
487
|
+
combineFn(queue.splice(0))();
|
|
488
|
+
setPendingCount(0);
|
|
489
|
+
}
|
|
490
|
+
function dismissAll(value) {
|
|
491
|
+
combineFn(active.splice(0))(multiple ? undefined : value);
|
|
492
|
+
dismissPending();
|
|
493
|
+
}
|
|
494
|
+
function render(callback) {
|
|
495
|
+
return new Promise(function (resolvePromise) {
|
|
496
|
+
var next = function next(value) {
|
|
497
|
+
if (arrRemove(active, resolvePromise)) {
|
|
498
|
+
resolvePromise(value);
|
|
499
|
+
setImmediate(function () {
|
|
500
|
+
(queue.shift() || noop)(true);
|
|
501
|
+
});
|
|
424
502
|
}
|
|
425
|
-
|
|
503
|
+
return root && !queue[0] && !active[0] ? closeFlyout(root) : resolve();
|
|
504
|
+
};
|
|
505
|
+
active.push(resolvePromise);
|
|
506
|
+
setPendingCount(queue.length);
|
|
507
|
+
callback(next);
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
if (multiple) {
|
|
511
|
+
childProps = {
|
|
512
|
+
closeOnBlur: false
|
|
513
|
+
};
|
|
514
|
+
props = extend({}, props, childProps);
|
|
515
|
+
} else {
|
|
516
|
+
childProps = props && pick(props, ['className', 'focus', 'modal', 'container']);
|
|
517
|
+
}
|
|
518
|
+
_(controller, {
|
|
519
|
+
root: root,
|
|
520
|
+
mode: mode,
|
|
521
|
+
props: childProps,
|
|
522
|
+
enqueue: function enqueue(callback) {
|
|
523
|
+
if (root && !isFlyoutOpen(root)) {
|
|
524
|
+
openDialog(root, props).then(dismissAll);
|
|
426
525
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
lock(root, promise);
|
|
526
|
+
if (queue.length || active.length >= (multiple ? props.concurrent || Infinity : 1)) {
|
|
527
|
+
return new Promise(function (resolve) {
|
|
528
|
+
queue.push(function (renderNext) {
|
|
529
|
+
resolve(renderNext && render(callback));
|
|
530
|
+
});
|
|
531
|
+
setPendingCount(queue.length);
|
|
532
|
+
});
|
|
435
533
|
}
|
|
436
|
-
return
|
|
534
|
+
return render(callback);
|
|
437
535
|
}
|
|
438
|
-
};
|
|
536
|
+
});
|
|
537
|
+
return extend(controller, {
|
|
538
|
+
dismissAll: dismissAll,
|
|
539
|
+
dismissPending: dismissPending
|
|
540
|
+
});
|
|
439
541
|
}
|
|
440
542
|
|
|
441
543
|
/**
|
|
442
544
|
* @param {import("./dialog").DialogProps} props
|
|
443
545
|
*/
|
|
444
546
|
function Dialog(props) {
|
|
445
|
-
var _props = useState({})[0];
|
|
446
|
-
var
|
|
447
|
-
return
|
|
547
|
+
var _props = extend(useState({})[0], props);
|
|
548
|
+
var element = useState(function () {
|
|
549
|
+
return createDialogElement(_props);
|
|
448
550
|
})[0];
|
|
449
|
-
extend(_props, props);
|
|
450
551
|
useEffect(function () {
|
|
451
|
-
var opened =
|
|
552
|
+
var opened = isFlyoutOpen(element);
|
|
452
553
|
if (either(opened, _props.isOpen)) {
|
|
453
554
|
if (!opened) {
|
|
454
|
-
|
|
555
|
+
openDialog(element, _props);
|
|
455
556
|
} else {
|
|
456
|
-
|
|
557
|
+
closeFlyout(element);
|
|
457
558
|
}
|
|
458
559
|
}
|
|
459
560
|
}, [_props.isOpen]);
|
|
460
561
|
useEffect(function () {
|
|
461
|
-
return
|
|
462
|
-
}, [
|
|
463
|
-
return /*#__PURE__*/external_commonjs_react_dom_commonjs2_react_dom_amd_react_dom_root_ReactDOM_.createPortal(props.children,
|
|
562
|
+
return closeFlyout.bind(0, element);
|
|
563
|
+
}, []);
|
|
564
|
+
return /*#__PURE__*/external_commonjs_react_dom_commonjs2_react_dom_amd_react_dom_root_ReactDOM_.createPortal(props.children, element);
|
|
464
565
|
}
|
|
465
566
|
;// CONCATENATED MODULE: ./|umd|/zeta-dom/events.js
|
|
466
567
|
|
|
@@ -493,7 +594,7 @@ var animateIn = external_commonjs_brew_js_commonjs2_brew_js_amd_brew_js_root_bre
|
|
|
493
594
|
|
|
494
595
|
|
|
495
596
|
|
|
496
|
-
var
|
|
597
|
+
var view_ = createPrivateStore();
|
|
497
598
|
var root = zeta_dom_dom.root;
|
|
498
599
|
var routeMap = new Map();
|
|
499
600
|
var usedParams = {};
|
|
@@ -502,7 +603,7 @@ var emitter = new EventContainer();
|
|
|
502
603
|
var rootContext = freeze(extend(new ViewContext(), {
|
|
503
604
|
container: root
|
|
504
605
|
}));
|
|
505
|
-
var rootState =
|
|
606
|
+
var rootState = view_(rootContext);
|
|
506
607
|
var StateContext = /*#__PURE__*/createContext(rootContext);
|
|
507
608
|
var errorView;
|
|
508
609
|
/** @type {Partial<Zeta.ZetaEventType<"beforepageload", Brew.RouterEventMap, Element>>} */
|
|
@@ -531,7 +632,7 @@ function ViewContext(view, page, parent) {
|
|
|
531
632
|
var self = this;
|
|
532
633
|
defineOwnProperty(self, 'view', view || null, true);
|
|
533
634
|
defineOwnProperty(self, 'parent', parent || null, true);
|
|
534
|
-
|
|
635
|
+
view_(self, {
|
|
535
636
|
children: [],
|
|
536
637
|
setPage: defineObservableProperty(self, 'page', page || null, true),
|
|
537
638
|
setActive: defineObservableProperty(self, 'active', !!page, true)
|
|
@@ -548,12 +649,12 @@ function ViewContext(view, page, parent) {
|
|
|
548
649
|
defineOwnProperty(ViewContext, 'root', rootContext, true);
|
|
549
650
|
definePrototype(ViewContext, {
|
|
550
651
|
getChildren: function getChildren() {
|
|
551
|
-
return map(
|
|
652
|
+
return map(view_(this).children, function (v) {
|
|
552
653
|
return v.currentContext;
|
|
553
654
|
});
|
|
554
655
|
},
|
|
555
656
|
setErrorView: function setErrorView(errorView, error) {
|
|
556
|
-
var wrapper =
|
|
657
|
+
var wrapper = view_(this).wrapper;
|
|
557
658
|
return wrapper && errorView && !wrapper.setState({
|
|
558
659
|
error: error,
|
|
559
660
|
errorView: errorView
|
|
@@ -566,7 +667,7 @@ definePrototype(ViewContext, {
|
|
|
566
667
|
function ErrorBoundary(props) {
|
|
567
668
|
Component.call(this, props);
|
|
568
669
|
this.state = {};
|
|
569
|
-
|
|
670
|
+
view_(props.context).wrapper = this;
|
|
570
671
|
}
|
|
571
672
|
definePrototype(ErrorBoundary, Component, {
|
|
572
673
|
componentDidMount: function componentDidMount() {
|
|
@@ -638,7 +739,7 @@ ViewContainer.contextType = StateContext;
|
|
|
638
739
|
definePrototype(ViewContainer, Component, {
|
|
639
740
|
componentDidMount: function componentDidMount() {
|
|
640
741
|
var self = this;
|
|
641
|
-
var parent =
|
|
742
|
+
var parent = view_(self.context).children;
|
|
642
743
|
var unwatch = watch(app_app.route, function () {
|
|
643
744
|
self.setActive(self.getViewComponent() === (self.currentContext || '').view);
|
|
644
745
|
});
|
|
@@ -731,7 +832,7 @@ definePrototype(ViewContainer, Component, {
|
|
|
731
832
|
});
|
|
732
833
|
self.views.shift();
|
|
733
834
|
self.setContext(context);
|
|
734
|
-
extend(self,
|
|
835
|
+
extend(self, view_(context));
|
|
735
836
|
state.rendered++;
|
|
736
837
|
animateIn(element, 'show', '[brew-view]', true);
|
|
737
838
|
resolve();
|
|
@@ -1883,15 +1984,12 @@ definePrototype(UnmanagedClassNameMixin, ClassNameMixin, {
|
|
|
1883
1984
|
|
|
1884
1985
|
|
|
1885
1986
|
|
|
1987
|
+
|
|
1886
1988
|
function extendSelf(options) {
|
|
1887
1989
|
extend(this, options);
|
|
1888
1990
|
}
|
|
1889
1991
|
function createUseFunction(ctor) {
|
|
1890
|
-
return
|
|
1891
|
-
var mixin = useMixin(ctor);
|
|
1892
|
-
(mixin.withOptions || extendSelf).apply(mixin, arguments);
|
|
1893
|
-
return mixin;
|
|
1894
|
-
};
|
|
1992
|
+
return useMixin.bind(0, ctor);
|
|
1895
1993
|
}
|
|
1896
1994
|
var useAnimateMixin = /*#__PURE__*/createUseFunction(AnimateMixin);
|
|
1897
1995
|
var useAnimateSequenceMixin = /*#__PURE__*/createUseFunction(AnimateSequenceMixin);
|
|
@@ -1902,10 +2000,12 @@ var useLoadingStateMixin = /*#__PURE__*/createUseFunction(LoadingStateMixin);
|
|
|
1902
2000
|
var useScrollableMixin = /*#__PURE__*/createUseFunction(ScrollableMixin);
|
|
1903
2001
|
var useScrollIntoViewMixin = /*#__PURE__*/createUseFunction(ScrollIntoViewMixin);
|
|
1904
2002
|
var useUnmanagedClassNameMixin = /*#__PURE__*/createUseFunction(UnmanagedClassNameMixin);
|
|
1905
|
-
function useMixin(ctor) {
|
|
1906
|
-
|
|
2003
|
+
function useMixin(ctor, options) {
|
|
2004
|
+
var mixin = useSingleton(function () {
|
|
1907
2005
|
return new ctor();
|
|
1908
|
-
}).reset();
|
|
2006
|
+
}, []).reset();
|
|
2007
|
+
(mixin.withOptions || extendSelf).call(mixin, options);
|
|
2008
|
+
return mixin;
|
|
1909
2009
|
}
|
|
1910
2010
|
function useMixinRef(mixin) {
|
|
1911
2011
|
return mixin && mixin.getMixin().reset();
|