brew-js-react 0.4.6 → 0.4.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/dist/brew-js-react.js +59 -36
- 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/i18n.d.ts +6 -3
- package/i18n.js +18 -16
- package/mixin.d.ts +1 -1
- package/mixins/AnimateSequenceMixin.js +9 -2
- package/package.json +1 -1
- package/view.js +28 -18
package/dist/brew-js-react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! brew-js-react v0.4.
|
|
1
|
+
/*! brew-js-react v0.4.7 | (c) misonou | https://hackmd.io/@misonou/brew-js-react */
|
|
2
2
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
3
3
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
4
4
|
module.exports = factory(require("brew-js"), require("react"), require("react-dom"), (function webpackLoadOptionalExternalModule() { try { return require("react-dom/client"); } catch(e) {} }()), require("zeta-dom"), require("zeta-dom-react"), require("waterpipe"));
|
|
@@ -257,6 +257,7 @@ var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_
|
|
|
257
257
|
noop = _lib$util.noop,
|
|
258
258
|
pipe = _lib$util.pipe,
|
|
259
259
|
either = _lib$util.either,
|
|
260
|
+
sameValueZero = _lib$util.sameValueZero,
|
|
260
261
|
is = _lib$util.is,
|
|
261
262
|
isUndefinedOrNull = _lib$util.isUndefinedOrNull,
|
|
262
263
|
isArray = _lib$util.isArray,
|
|
@@ -321,6 +322,7 @@ var _lib$util = external_commonjs_zeta_dom_commonjs2_zeta_dom_amd_zeta_dom_root_
|
|
|
321
322
|
lcfirst = _lib$util.lcfirst,
|
|
322
323
|
trim = _lib$util.trim,
|
|
323
324
|
matchWord = _lib$util.matchWord,
|
|
325
|
+
matchWordMulti = _lib$util.matchWordMulti,
|
|
324
326
|
htmlDecode = _lib$util.htmlDecode,
|
|
325
327
|
resolve = _lib$util.resolve,
|
|
326
328
|
reject = _lib$util.reject,
|
|
@@ -617,6 +619,24 @@ var view_event = {};
|
|
|
617
619
|
onAppInit(function () {
|
|
618
620
|
app_app.on('beforepageload', function (e) {
|
|
619
621
|
view_event = e;
|
|
622
|
+
e.waitFor(new Promise(function (resolve) {
|
|
623
|
+
(function updateViewRecursive(next) {
|
|
624
|
+
if (!next[0]) {
|
|
625
|
+
return resolve();
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
resolveAll(map(next, function (v) {
|
|
629
|
+
return new Promise(function (resolve) {
|
|
630
|
+
v.onRender = resolve;
|
|
631
|
+
v.forceUpdate();
|
|
632
|
+
});
|
|
633
|
+
})).then(function () {
|
|
634
|
+
updateViewRecursive(map(next, function (v) {
|
|
635
|
+
return v.children;
|
|
636
|
+
}));
|
|
637
|
+
});
|
|
638
|
+
})(_(rootContext).children);
|
|
639
|
+
}));
|
|
620
640
|
|
|
621
641
|
_(rootContext).setPage(app_app.page);
|
|
622
642
|
});
|
|
@@ -627,6 +647,7 @@ function ViewContext(view, page) {
|
|
|
627
647
|
defineOwnProperty(self, 'view', view, true);
|
|
628
648
|
|
|
629
649
|
_(self, {
|
|
650
|
+
children: [],
|
|
630
651
|
setPage: defineObservableProperty(self, 'page', page, true),
|
|
631
652
|
setActive: defineObservableProperty(self, 'active', true, true)
|
|
632
653
|
});
|
|
@@ -698,33 +719,27 @@ definePrototype(ErrorBoundary, external_commonjs_react_commonjs2_react_amd_react
|
|
|
698
719
|
|
|
699
720
|
function ViewContainer() {
|
|
700
721
|
external_commonjs_react_commonjs2_react_amd_react_root_React_.Component.apply(this, arguments);
|
|
701
|
-
this.stateId = history.state;
|
|
702
722
|
}
|
|
703
723
|
|
|
704
724
|
ViewContainer.contextType = StateContext;
|
|
705
725
|
definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react_root_React_.Component, {
|
|
706
726
|
componentDidMount: function componentDidMount() {
|
|
707
|
-
/** @type {any} */
|
|
708
727
|
var self = this;
|
|
728
|
+
|
|
729
|
+
var parent = _(self.context).children;
|
|
730
|
+
|
|
731
|
+
parent.push(self);
|
|
709
732
|
self.componentWillUnmount = combineFn(watch(app_app.route, function () {
|
|
710
733
|
(self.setActive || noop)(self.getViewComponent() === self.currentViewComponent);
|
|
711
|
-
}),
|
|
712
|
-
self
|
|
713
|
-
|
|
714
|
-
if (self.context === rootContext || self.updateOnNext) {
|
|
715
|
-
view_event.waitFor(new Promise(function (resolve) {
|
|
716
|
-
self.onRender = resolve;
|
|
717
|
-
}));
|
|
718
|
-
self.updateView();
|
|
719
|
-
self.forceUpdate();
|
|
720
|
-
}
|
|
721
|
-
}));
|
|
734
|
+
}), function () {
|
|
735
|
+
arrRemove(parent, self);
|
|
736
|
+
});
|
|
722
737
|
},
|
|
723
738
|
render: function render() {
|
|
724
739
|
/** @type {any} */
|
|
725
740
|
var self = this;
|
|
726
741
|
|
|
727
|
-
if (
|
|
742
|
+
if (self.context.active) {
|
|
728
743
|
self.updateView();
|
|
729
744
|
}
|
|
730
745
|
|
|
@@ -734,21 +749,20 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
|
|
|
734
749
|
updateView: function updateView() {
|
|
735
750
|
var self = this;
|
|
736
751
|
var V = self.getViewComponent();
|
|
737
|
-
|
|
752
|
+
var viewChanged = V !== self.currentViewComponent;
|
|
738
753
|
|
|
739
|
-
if (V) {
|
|
754
|
+
if (V && (viewChanged || !(self.children || '')[0])) {
|
|
740
755
|
// ensure the current path actually corresponds to the matched view
|
|
741
756
|
// when some views are not included in the list of allowed views
|
|
742
757
|
var targetPath = resolvePath(V, getCurrentParams(V, true));
|
|
743
758
|
|
|
744
759
|
if (targetPath !== removeQueryAndHash(app_app.path)) {
|
|
745
760
|
app_app.navigate(targetPath, true);
|
|
746
|
-
self.updateOnNext = true;
|
|
747
761
|
return;
|
|
748
762
|
}
|
|
749
763
|
}
|
|
750
764
|
|
|
751
|
-
if (V &&
|
|
765
|
+
if (V && viewChanged) {
|
|
752
766
|
var prevElement = self.currentElement;
|
|
753
767
|
|
|
754
768
|
if (prevElement) {
|
|
@@ -1148,19 +1162,19 @@ if (toPrimitive) {
|
|
|
1148
1162
|
}
|
|
1149
1163
|
|
|
1150
1164
|
function createCallback(translate) {
|
|
1151
|
-
var callback = function callback(key, data) {
|
|
1152
|
-
var result = translate(key, data, true);
|
|
1165
|
+
var callback = function callback(key, data, lang) {
|
|
1166
|
+
var result = translate(key, data, lang, true);
|
|
1153
1167
|
return result !== undefined ? result : key;
|
|
1154
1168
|
};
|
|
1155
1169
|
|
|
1156
1170
|
return extend(callback, {
|
|
1157
|
-
html: function html(id, data) {
|
|
1171
|
+
html: function html(id, data, lang) {
|
|
1158
1172
|
return {
|
|
1159
|
-
__html: translate(id, data)
|
|
1173
|
+
__html: translate(id, data, lang)
|
|
1160
1174
|
};
|
|
1161
1175
|
},
|
|
1162
|
-
lazy: function lazy(id, data) {
|
|
1163
|
-
return new TString(translate.bind(0, id, data, true));
|
|
1176
|
+
lazy: function lazy(id, data, lang) {
|
|
1177
|
+
return new TString(translate.bind(0, id, data, lang, true));
|
|
1164
1178
|
}
|
|
1165
1179
|
});
|
|
1166
1180
|
}
|
|
@@ -1190,36 +1204,38 @@ function makeTranslation(resources, defaultLang) {
|
|
|
1190
1204
|
}
|
|
1191
1205
|
}
|
|
1192
1206
|
|
|
1193
|
-
function translate(key, data, noEncode) {
|
|
1207
|
+
function translate(key, data, lang, noEncode) {
|
|
1194
1208
|
var prefix = re.test(key) ? RegExp.$1 : '';
|
|
1195
1209
|
var name = prefix ? key.slice(RegExp.lastMatch.length) : key;
|
|
1196
|
-
return getTranslation(prefix, name, data, noEncode, app_app.language);
|
|
1210
|
+
return getTranslation(prefix, name, data, noEncode, lang || app_app.language);
|
|
1197
1211
|
}
|
|
1198
1212
|
|
|
1199
1213
|
function getTranslationCallback() {
|
|
1214
|
+
var currentLang = String(this);
|
|
1200
1215
|
var prefix = makeArray(arguments);
|
|
1201
|
-
var key = prefix.join(' ');
|
|
1202
|
-
return cache[key] || (cache[key] = createCallback(function (key, data, noEncode) {
|
|
1203
|
-
|
|
1216
|
+
var key = currentLang + ' ' + prefix.join(' ');
|
|
1217
|
+
return cache[key] || (cache[key] = prefix[0] ? createCallback(function (key, data, lang, noEncode) {
|
|
1218
|
+
lang = lang || currentLang || app_app.language;
|
|
1204
1219
|
return single(prefix, function (v) {
|
|
1205
1220
|
return getTranslation(v, key, data, noEncode, lang);
|
|
1206
1221
|
});
|
|
1222
|
+
}) : createCallback(function (key, data, lang, noEncode) {
|
|
1223
|
+
return translate(key, data, lang || currentLang, noEncode);
|
|
1207
1224
|
}));
|
|
1208
1225
|
}
|
|
1209
1226
|
|
|
1210
1227
|
function useTranslation() {
|
|
1211
1228
|
var language = useLanguage();
|
|
1212
|
-
var t = getTranslationCallback.apply(
|
|
1229
|
+
var t = getTranslationCallback.apply(language, arguments);
|
|
1213
1230
|
return {
|
|
1214
1231
|
language: language,
|
|
1215
1232
|
t: t
|
|
1216
1233
|
};
|
|
1217
1234
|
}
|
|
1218
1235
|
|
|
1219
|
-
cache[''] = createCallback(translate);
|
|
1220
1236
|
return {
|
|
1221
|
-
translate:
|
|
1222
|
-
getTranslation: getTranslationCallback,
|
|
1237
|
+
translate: createCallback(translate),
|
|
1238
|
+
getTranslation: getTranslationCallback.bind(''),
|
|
1223
1239
|
useTranslation: useTranslation,
|
|
1224
1240
|
keys: function keys(prefix) {
|
|
1225
1241
|
return util_keys(resources[defaultLang][prefix] || empty);
|
|
@@ -1529,13 +1545,20 @@ function AnimateSequenceMixin() {
|
|
|
1529
1545
|
self.item = new AnimateSequenceItemMixin(self.className);
|
|
1530
1546
|
}
|
|
1531
1547
|
definePrototype(AnimateSequenceMixin, AnimateMixin, {
|
|
1548
|
+
withOptions: function withOptions(options) {
|
|
1549
|
+
this.selector = options;
|
|
1550
|
+
return this;
|
|
1551
|
+
},
|
|
1532
1552
|
reset: function reset() {
|
|
1533
1553
|
this.item.reset();
|
|
1534
1554
|
return AnimateSequenceMixinSuper.reset.call(this);
|
|
1535
1555
|
},
|
|
1536
1556
|
getCustomAttributes: function getCustomAttributes() {
|
|
1537
|
-
|
|
1538
|
-
|
|
1557
|
+
var self = this;
|
|
1558
|
+
return extend({}, AnimateSequenceMixinSuper.getCustomAttributes.call(self), {
|
|
1559
|
+
'animate-in': null,
|
|
1560
|
+
'animate-sequence-type': (self.effects || []).join(' '),
|
|
1561
|
+
'animate-sequence': self.selector || '.' + self.className
|
|
1539
1562
|
});
|
|
1540
1563
|
},
|
|
1541
1564
|
clone: function clone() {
|