@merkur/plugin-router 0.29.1 → 0.30.0
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/lib/index.es5.js +1 -1
- package/lib/index.es9.cjs +12 -50
- package/lib/index.es9.mjs +12 -43
- package/package.json +5 -5
package/lib/index.es5.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==t)return;var n,o,u=[],i=!0,s=!1;try{for(t=t.call(e);!(i=(n=t.next()).done)&&(u.push(n.value),!r||u.length!==r);i=!0);}catch(e){s=!0,o=e}finally{try{i||null==t.return||t.return()}finally{if(s)throw o}}return u}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function t(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function n(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?t(Object(n),!0).forEach((function(r){o(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))}))}return e}function o(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function u(e,r,t,n,o,u,i){try{var s=e[u](i),a=s.value}catch(e){return void t(e)}s.done?r(a):Promise.resolve(a).then(n,o)}function i(e){return function(){var r=this,t=arguments;return new Promise((function(n,o){var i=e.apply(r,t);function s(e){u(i,n,o,s,a,"next",e)}function a(e){u(i,n,o,s,a,"throw",e)}s(void 0)}))}}function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}require("regenerator-runtime/runtime.js"),require("core-js/modules/es.object.define-property.js"),require("core-js/modules/es.object.freeze.js"),require("core-js/modules/es.string.link.js"),require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.symbol.js"),require("core-js/modules/es.symbol.description.js"),require("core-js/modules/es.symbol.iterator.js"),require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.array.filter.js"),require("core-js/modules/es.object.get-own-property-descriptor.js"),require("core-js/modules/es.array.for-each.js"),require("core-js/modules/web.dom-collections.for-each.js"),require("core-js/modules/es.object.get-own-property-descriptors.js"),require("core-js/modules/es.object.define-properties.js"),require("core-js/modules/es.array.is-array.js"),require("core-js/modules/es.array.slice.js"),require("core-js/modules/es.function.name.js"),require("core-js/modules/es.array.from.js"),require("core-js/modules/es.regexp.exec.js"),Object.defineProperty(exports,"__esModule",{value:!0});var a=require("@merkur/core"),c=require("universal-router"),p=require("universal-router/generateUrls");function l(e){return e&&"object"===s(e)&&"default"in e?e:{default:e}}var f=l(c),d=l(p),m=Object.freeze({REDIRECT:"@merkur/plugin-router.redirect"}),y="development",h="undefined"!=typeof process&&process&&process.env?process.env.NODE_ENV:y;function g(e,r){return b.apply(this,arguments)}function b(){return b=i(regeneratorRuntime.mark((function e(r,t){var n,o,u,i=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!r.$in.router.isBootstrapCalled){e.next=2;break}return e.abrupt("return");case 2:for(r.$in.router.isBootstrapCalled=!0,n=i.length,o=new Array(n>2?n-2:0),u=2;u<n;u++)o[u-2]=i[u];return e.abrupt("return",t.apply(void 0,o));case 5:case"end":return e.stop()}}),e)}))),b.apply(this,arguments)}function j(e,r){return v.apply(this,arguments)}function v(){return v=i(regeneratorRuntime.mark((function r(t,o){var u,i,s,c,p,l,f,d,m,y,h=arguments;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(u=t.$in.router,i=h.length,s=new Array(i>2?i-2:0),c=2;c<i;c++)s[c-2]=h[c];if(u.isMounting||t.props.pathname===u.pathname){r.next=7;break}return r.next=5,S.apply(void 0,[t].concat(s));case 5:return r.next=7,E.apply(void 0,[t].concat(s));case 7:if(a.isFunction(u.route.load)){r.next=9;break}throw new Error("The load method is mandatory.");case 9:return p=a.isFunction(o)?o.apply(void 0,[t].concat(s)):Promise.resolve({}),l=u.route.load(t,{route:u.route,args:s,globalState:p}),r.next=13,Promise.all([p,l]);case 13:return f=r.sent,d=e(f,2),m=d[0],y=d[1],r.abrupt("return",n(n({},m),y));case 18:case"end":return r.stop()}}),r)}))),v.apply(this,arguments)}function w(e,r){return x.apply(this,arguments)}function x(){return x=i(regeneratorRuntime.mark((function e(r,t){var n,o,u,i,s,c=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=c.length,o=new Array(n>2?n-2:0),u=2;u<n;u++)o[u-2]=c[u];return e.next=3,r.bootstrap.apply(r,o);case 3:if((i=r.$in.router).route){e.next=8;break}return e.next=7,$(r);case 7:i.isMounting=!0;case 8:return e.next=10,t.apply(void 0,o);case 10:if(s=e.sent,!i.isMounting||!a.isFunction(i.route.init)){e.next=14;break}return e.next=14,i.route.init(r,{route:i.route,args:o});case 14:return a.isFunction(i.route.activate)&&C()&&!i.isRouteActivated&&(i.isRouteActivated=!0,i.route.activate(r,{route:i.route,args:o})),i.isMounting=!1,e.abrupt("return",s);case 17:case"end":return e.stop()}}),e)}))),x.apply(this,arguments)}function k(e,r){return R.apply(this,arguments)}function R(){return R=i(regeneratorRuntime.mark((function e(r,t){var n,o,u,i,s,c=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=c.length,o=new Array(n>2?n-2:0),u=2;u<n;u++)o[u-2]=c[u];return e.next=3,t.apply(void 0,o);case 3:return i=e.sent,s=r.$in.router,a.isFunction(s.route.activate)&&C()&&!s.isRouteActivated&&(s.isRouteActivated=!0,s.route.activate(r,{route:s.route,args:o})),e.abrupt("return",i);case 7:case"end":return e.stop()}}),e)}))),R.apply(this,arguments)}function q(e,r){return O.apply(this,arguments)}function O(){return O=i(regeneratorRuntime.mark((function e(r,t){var n,o,u,i,s=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=s.length,o=new Array(n>2?n-2:0),u=2;u<n;u++)o[u-2]=s[u];return e.next=3,t.apply(void 0,o);case 3:return i=e.sent,e.next=6,S.apply(void 0,[r].concat(o));case 6:return e.abrupt("return",i);case 7:case"end":return e.stop()}}),e)}))),O.apply(this,arguments)}function $(e){return A.apply(this,arguments)}function A(){return(A=i(regeneratorRuntime.mark((function e(r){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(h!==y){e.next=5;break}if(r.props.pathname){e.next=3;break}throw new Error("The props pathname is not defined.");case 3:if(r.$dependencies.router){e.next=5;break}throw new Error("You must add calling of createRouter(widget, routes, options) to widget.setup method.");case 5:return e.next=7,r.$dependencies.router.resolve({pathname:r.props.pathname,widget:r});case 7:return t=e.sent,r.$in.router.route=t,r.$in.router.pathname=r.props.pathname,e.abrupt("return",t);case 11:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function E(e){return P.apply(this,arguments)}function P(){return P=i(regeneratorRuntime.mark((function e(r){var t,n,o,u,i=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,$(r);case 2:if(t=e.sent,!a.isFunction(t.init)){e.next=7;break}for(n=i.length,o=new Array(n>1?n-1:0),u=1;u<n;u++)o[u-1]=i[u];return e.next=7,t.init(r,{route:t,args:o});case 7:case"end":return e.stop()}}),e)}))),P.apply(this,arguments)}function S(e){return M.apply(this,arguments)}function M(){return M=i(regeneratorRuntime.mark((function e(r){var t,n,o,u,i,s,c=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.$in.router,n=t.route,o=t.isRouteActivated,!n){e.next=10;break}for(u=c.length,i=new Array(u>1?u-1:0),s=1;s<u;s++)i[s-1]=c[s];if(!a.isFunction(n.deactivate)||!0!==o){e.next=7;break}return e.next=7,n.deactivate(r,{route:n,args:i});case 7:if(!a.isFunction(n.destroy)){e.next=10;break}return e.next=10,n.destroy(r,{route:n,args:i});case 10:t.isRouteActivated=!1;case 11:case"end":return e.stop()}}),e)}))),M.apply(this,arguments)}function C(){return"undefined"!=typeof window}exports.createRouter=function(e,r,t){e.$dependencies.router=new f.default(r,t),e.$dependencies.link=d.default(e.$dependencies.router)},exports.routerPlugin=function(){return{setup:function(e){return i(regeneratorRuntime.mark((function r(){return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return e=n(n({},{router:{redirect:function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e.emit(m.REDIRECT,n({url:r},t))},link:function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e.$dependencies.link(r,t)},getCurrentRoute:function(e){return e.$in.router.route}}}),e),e.$in.router={route:null,pathname:null,isMounting:!1,isRouteActivated:!1,isBootstrapCalled:!1},a.bindWidgetToFunctions(e,e.router),r.abrupt("return",e);case 4:case"end":return r.stop()}}),r)})))()},create:function(e){return i(regeneratorRuntime.mark((function r(){return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(h!==y){r.next=5;break}if(e.$in.component){r.next=3;break}throw new Error("You must install missing plugin: npm i @merkur/plugin-component");case 3:if(e.$in.eventEmitter){r.next=5;break}throw new Error("You must install missing plugin: npm i @merkur/plugin-event-emitter");case 5:return e.$in.component.lifeCycle=a.setDefaultValueForUndefined(e.$in.component.lifeCycle,["load"],(function(){})),a.hookMethod(e,"$in.component.lifeCycle.load",j),a.hookMethod(e,"bootstrap",g),a.hookMethod(e,"mount",w),a.hookMethod(e,"unmount",q),a.hookMethod(e,"update",k),r.abrupt("return",e);case 12:case"end":return r.stop()}}),r)})))()}}};
|
|
1
|
+
"use strict";function e(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==t)return;var n,o,i=[],u=!0,a=!1;try{for(t=t.call(e);!(u=(n=t.next()).done)&&(i.push(n.value),!r||i.length!==r);u=!0);}catch(e){a=!0,o=e}finally{try{u||null==t.return||t.return()}finally{if(a)throw o}}return i}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function t(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */t=function(){return e};var e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(e,r,t){e[r]=t.value},i="function"==typeof Symbol?Symbol:{},u=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function l(e,r,t){return Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}),e[r]}try{l({},"")}catch(e){l=function(e,r,t){return e[r]=t}}function f(e,r,t,n){var i=r&&r.prototype instanceof d?r:d,u=Object.create(i.prototype),a=new L(n||[]);return o(u,"_invoke",{value:k(e,t,a)}),u}function p(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}e.wrap=f;var h={};function d(){}function y(){}function m(){}var v={};l(v,u,(function(){return this}));var g=Object.getPrototypeOf,b=g&&g(g(A([])));b&&b!==r&&n.call(b,u)&&(v=b);var j=m.prototype=d.prototype=Object.create(v);function w(e){["next","throw","return"].forEach((function(r){l(e,r,(function(e){return this._invoke(r,e)}))}))}function x(e,r){function t(o,i,u,a){var c=p(e[o],e,i);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==s(f)&&n.call(f,"__await")?r.resolve(f.__await).then((function(e){t("next",e,u,a)}),(function(e){t("throw",e,u,a)})):r.resolve(f).then((function(e){l.value=e,u(l)}),(function(e){return t("throw",e,u,a)}))}a(c.arg)}var i;o(this,"_invoke",{value:function(e,n){function o(){return new r((function(r,o){t(e,n,r,o)}))}return i=i?i.then(o,o):o()}})}function k(e,r,t){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(t.method=o,t.arg=i;;){var u=t.delegate;if(u){var a=E(u,t);if(a){if(a===h)continue;return a}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var s=p(e,r,t);if("normal"===s.type){if(n=t.done?"completed":"suspendedYield",s.arg===h)continue;return{value:s.arg,done:t.done}}"throw"===s.type&&(n="completed",t.method="throw",t.arg=s.arg)}}}function E(e,r){var t=e.iterator[r.method];if(void 0===t){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=void 0,E(e,r),"throw"===r.method))return h;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=p(t,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,h;var o=n.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,h):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,h)}function O(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function q(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function L(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function A(e){if(e){var r=e[u];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var t=-1,o=function r(){for(;++t<e.length;)if(n.call(e,t))return r.value=e[t],r.done=!1,r;return r.value=void 0,r.done=!0,r};return o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return y.prototype=m,o(j,"constructor",{value:m,configurable:!0}),o(m,"constructor",{value:y,configurable:!0}),y.displayName=l(m,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===y||"GeneratorFunction"===(r.displayName||r.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,l(e,c,"GeneratorFunction")),e.prototype=Object.create(j),e},e.awrap=function(e){return{__await:e}},w(x.prototype),l(x.prototype,a,(function(){return this})),e.AsyncIterator=x,e.async=function(r,t,n,o,i){void 0===i&&(i=Promise);var u=new x(f(r,t,n,o),i);return e.isGeneratorFunction(t)?u:u.next().then((function(e){return e.done?e.value:u.next()}))},w(j),l(j,c,"Generator"),l(j,u,(function(){return this})),l(j,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var r=Object(e),t=[];for(var n in r)t.push(n);return t.reverse(),function e(){for(;t.length;){var n=t.pop();if(n in r)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=A,L.prototype={constructor:L,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(q),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function t(t,n){return u.type="throw",u.arg=e,r.next=t,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return t("end");if(i.tryLoc<=this.prev){var a=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(a&&s){if(this.prev<i.catchLoc)return t(i.catchLoc,!0);if(this.prev<i.finallyLoc)return t(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return t(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return t(i.finallyLoc)}}}},abrupt:function(e,r){for(var t=this.tryEntries.length-1;t>=0;--t){var o=this.tryEntries[t];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var u=i?i.completion:{};return u.type=e,u.arg=r,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(u)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),h},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),q(t),h}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var o=n.arg;q(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={iterator:A(e),resultName:r,nextLoc:t},"next"===this.method&&(this.arg=void 0),h}},e}function n(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function o(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?n(Object(t),!0).forEach((function(r){i(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):n(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function i(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function u(e,r,t,n,o,i,u){try{var a=e[i](u),s=a.value}catch(e){return void t(e)}a.done?r(s):Promise.resolve(s).then(n,o)}function a(e){return function(){var r=this,t=arguments;return new Promise((function(n,o){var i=e.apply(r,t);function a(e){u(i,n,o,a,s,"next",e)}function s(e){u(i,n,o,a,s,"throw",e)}a(void 0)}))}}function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}require("core-js/modules/es.object.define-property.js"),require("core-js/modules/es.object.freeze.js"),require("core-js/modules/es.string.link.js"),require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.object.to-string.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.symbol.js"),require("core-js/modules/es.symbol.description.js"),require("core-js/modules/es.symbol.iterator.js"),require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.array.filter.js"),require("core-js/modules/es.object.get-own-property-descriptor.js"),require("core-js/modules/es.array.for-each.js"),require("core-js/modules/web.dom-collections.for-each.js"),require("core-js/modules/es.object.get-own-property-descriptors.js"),require("core-js/modules/es.object.define-properties.js"),require("core-js/modules/es.symbol.async-iterator.js"),require("core-js/modules/es.symbol.to-string-tag.js"),require("core-js/modules/es.json.to-string-tag.js"),require("core-js/modules/es.math.to-string-tag.js"),require("core-js/modules/es.object.create.js"),require("core-js/modules/es.object.get-prototype-of.js"),require("core-js/modules/es.function.name.js"),require("core-js/modules/es.object.set-prototype-of.js"),require("core-js/modules/es.array.reverse.js"),require("core-js/modules/es.array.slice.js"),require("core-js/modules/es.array.is-array.js"),require("core-js/modules/es.array.from.js"),require("core-js/modules/es.regexp.exec.js"),Object.defineProperty(exports,"__esModule",{value:!0});var c=require("@merkur/core"),l=require("universal-router"),f=require("universal-router/generateUrls");function p(e){return e&&"object"===s(e)&&"default"in e?e:{default:e}}var h=p(l),d=p(f),y=Object.freeze({REDIRECT:"@merkur/plugin-router.redirect"}),m="development",v="undefined"!=typeof process&&process&&process.env?process.env.NODE_ENV:m;function g(e,r){return b.apply(this,arguments)}function b(){return b=a(t().mark((function e(r,n){var o,i,u,a=arguments;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!r.$in.router.isBootstrapCalled){e.next=2;break}return e.abrupt("return");case 2:for(r.$in.router.isBootstrapCalled=!0,o=a.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=a[u];return e.abrupt("return",n.apply(void 0,i));case 5:case"end":return e.stop()}}),e)}))),b.apply(this,arguments)}function j(e,r){return w.apply(this,arguments)}function w(){return w=a(t().mark((function r(n,i){var u,a,s,l,f,p,h,d,y,m,v=arguments;return t().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(u=n.$in.router,a=v.length,s=new Array(a>2?a-2:0),l=2;l<a;l++)s[l-2]=v[l];if(u.isMounting||n.props.pathname===u.pathname){r.next=7;break}return r.next=5,_.apply(void 0,[n].concat(s));case 5:return r.next=7,$.apply(void 0,[n].concat(s));case 7:if(c.isFunction(u.route.load)){r.next=9;break}throw new Error("The load method is mandatory.");case 9:return f=c.isFunction(i)?i.apply(void 0,[n].concat(s)):Promise.resolve({}),p=u.route.load(n,{route:u.route,args:s,globalState:f}),r.next=13,Promise.all([f,p]);case 13:return h=r.sent,d=e(h,2),y=d[0],m=d[1],r.abrupt("return",o(o({},y),m));case 18:case"end":return r.stop()}}),r)}))),w.apply(this,arguments)}function x(e,r){return k.apply(this,arguments)}function k(){return k=a(t().mark((function e(r,n){var o,i,u,a,s,l=arguments;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=l.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=l[u];return e.next=3,r.bootstrap.apply(r,i);case 3:if((a=r.$in.router).route){e.next=8;break}return e.next=7,A(r);case 7:a.isMounting=!0;case 8:return e.next=10,n.apply(void 0,i);case 10:if(s=e.sent,!a.isMounting||!c.isFunction(a.route.init)){e.next=14;break}return e.next=14,a.route.init(r,{route:a.route,args:i});case 14:return c.isFunction(a.route.activate)&&R()&&!a.isRouteActivated&&(a.isRouteActivated=!0,a.route.activate(r,{route:a.route,args:i})),a.isMounting=!1,e.abrupt("return",s);case 17:case"end":return e.stop()}}),e)}))),k.apply(this,arguments)}function E(e,r){return O.apply(this,arguments)}function O(){return O=a(t().mark((function e(r,n){var o,i,u,a,s,l=arguments;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=l.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=l[u];return e.next=3,n.apply(void 0,i);case 3:return a=e.sent,s=r.$in.router,c.isFunction(s.route.activate)&&R()&&!s.isRouteActivated&&(s.isRouteActivated=!0,s.route.activate(r,{route:s.route,args:i})),e.abrupt("return",a);case 7:case"end":return e.stop()}}),e)}))),O.apply(this,arguments)}function q(e,r){return L.apply(this,arguments)}function L(){return L=a(t().mark((function e(r,n){var o,i,u,a,s=arguments;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(o=s.length,i=new Array(o>2?o-2:0),u=2;u<o;u++)i[u-2]=s[u];return e.next=3,n.apply(void 0,i);case 3:return a=e.sent,e.next=6,_.apply(void 0,[r].concat(i));case 6:return e.abrupt("return",a);case 7:case"end":return e.stop()}}),e)}))),L.apply(this,arguments)}function A(e){return P.apply(this,arguments)}function P(){return(P=a(t().mark((function e(r){var n;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(v!==m){e.next=5;break}if(r.props.pathname){e.next=3;break}throw new Error("The props pathname is not defined.");case 3:if(r.$dependencies.router){e.next=5;break}throw new Error("You must add calling of createRouter(widget, routes, options) to widget.setup method.");case 5:return e.next=7,r.$dependencies.router.resolve({pathname:r.props.pathname,widget:r});case 7:return n=e.sent,r.$in.router.route=n,r.$in.router.pathname=r.props.pathname,e.abrupt("return",n);case 11:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function $(e){return S.apply(this,arguments)}function S(){return S=a(t().mark((function e(r){var n,o,i,u,a=arguments;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,A(r);case 2:if(n=e.sent,!c.isFunction(n.init)){e.next=7;break}for(o=a.length,i=new Array(o>1?o-1:0),u=1;u<o;u++)i[u-1]=a[u];return e.next=7,n.init(r,{route:n,args:i});case 7:case"end":return e.stop()}}),e)}))),S.apply(this,arguments)}function _(e){return F.apply(this,arguments)}function F(){return F=a(t().mark((function e(r){var n,o,i,u,a,s,l=arguments;return t().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=r.$in.router,o=n.route,i=n.isRouteActivated,!o){e.next=10;break}for(u=l.length,a=new Array(u>1?u-1:0),s=1;s<u;s++)a[s-1]=l[s];if(!c.isFunction(o.deactivate)||!0!==i){e.next=7;break}return e.next=7,o.deactivate(r,{route:o,args:a});case 7:if(!c.isFunction(o.destroy)){e.next=10;break}return e.next=10,o.destroy(r,{route:o,args:a});case 10:n.isRouteActivated=!1;case 11:case"end":return e.stop()}}),e)}))),F.apply(this,arguments)}function R(){return"undefined"!=typeof window}exports.createRouter=function(e,r,t){e.$dependencies.router=new h.default(r,t),e.$dependencies.link=d.default(e.$dependencies.router)},exports.routerPlugin=function(){return{setup:function(e){return a(t().mark((function r(){return t().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return e=o(o({},{router:{redirect:function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};e.emit(y.REDIRECT,o({url:r},t))},link:function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e.$dependencies.link(r,t)},getCurrentRoute:function(e){return e.$in.router.route}}}),e),e.$in.router={route:null,pathname:null,isMounting:!1,isRouteActivated:!1,isBootstrapCalled:!1},c.bindWidgetToFunctions(e,e.router),r.abrupt("return",e);case 4:case"end":return r.stop()}}),r)})))()},create:function(e){return a(t().mark((function r(){return t().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(v!==m){r.next=5;break}if(e.$in.component){r.next=3;break}throw new Error("You must install missing plugin: npm i @merkur/plugin-component");case 3:if(e.$in.eventEmitter){r.next=5;break}throw new Error("You must install missing plugin: npm i @merkur/plugin-event-emitter");case 5:return e.$in.component.lifeCycle=c.setDefaultValueForUndefined(e.$in.component.lifeCycle,["load"],(function(){})),c.hookMethod(e,"$in.component.lifeCycle.load",j),c.hookMethod(e,"bootstrap",g),c.hookMethod(e,"mount",x),c.hookMethod(e,"unmount",q),c.hookMethod(e,"update",E),r.abrupt("return",e);case 12:case"end":return r.stop()}}),r)})))()}}};
|
package/lib/index.es9.cjs
CHANGED
|
@@ -3,38 +3,30 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var core = require('@merkur/core');
|
|
8
|
-
|
|
9
7
|
var UniversalRouter = require('universal-router');
|
|
10
|
-
|
|
11
8
|
var generateUrls = require('universal-router/generateUrls');
|
|
12
|
-
|
|
13
9
|
function _interopDefaultLegacy(e) {
|
|
14
10
|
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
15
11
|
'default': e
|
|
16
12
|
};
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
var UniversalRouter__default = /*#__PURE__*/_interopDefaultLegacy(UniversalRouter);
|
|
20
|
-
|
|
21
15
|
var generateUrls__default = /*#__PURE__*/_interopDefaultLegacy(generateUrls);
|
|
22
|
-
|
|
23
16
|
var RouterEvents = Object.freeze({
|
|
24
17
|
REDIRECT: '@merkur/plugin-router.redirect'
|
|
25
18
|
});
|
|
26
19
|
const DEV = 'development';
|
|
27
20
|
const ENV = typeof process !== 'undefined' && process && process.env ? process.env.NODE_ENV : DEV;
|
|
28
|
-
|
|
29
21
|
function createRouter(widget, routes, options) {
|
|
30
22
|
widget.$dependencies.router = new UniversalRouter__default["default"](routes, options);
|
|
31
23
|
widget.$dependencies.link = generateUrls__default["default"](widget.$dependencies.router);
|
|
32
24
|
}
|
|
33
|
-
|
|
34
25
|
function routerPlugin() {
|
|
35
26
|
return {
|
|
36
27
|
async setup(widget) {
|
|
37
|
-
widget = {
|
|
28
|
+
widget = {
|
|
29
|
+
...routerAPI(),
|
|
38
30
|
...widget
|
|
39
31
|
};
|
|
40
32
|
widget.$in.router = {
|
|
@@ -47,18 +39,15 @@ function routerPlugin() {
|
|
|
47
39
|
core.bindWidgetToFunctions(widget, widget.router);
|
|
48
40
|
return widget;
|
|
49
41
|
},
|
|
50
|
-
|
|
51
42
|
async create(widget) {
|
|
52
43
|
if (ENV === DEV) {
|
|
53
44
|
if (!widget.$in.component) {
|
|
54
45
|
throw new Error('You must install missing plugin: npm i @merkur/plugin-component');
|
|
55
46
|
}
|
|
56
|
-
|
|
57
47
|
if (!widget.$in.eventEmitter) {
|
|
58
48
|
throw new Error('You must install missing plugin: npm i @merkur/plugin-event-emitter');
|
|
59
49
|
}
|
|
60
50
|
}
|
|
61
|
-
|
|
62
51
|
widget.$in.component.lifeCycle = core.setDefaultValueForUndefined(widget.$in.component.lifeCycle, ['load'], () => {});
|
|
63
52
|
core.hookMethod(widget, '$in.component.lifeCycle.load', loadHook);
|
|
64
53
|
core.hookMethod(widget, 'bootstrap', bootstrapHook);
|
|
@@ -67,10 +56,8 @@ function routerPlugin() {
|
|
|
67
56
|
core.hookMethod(widget, 'update', updateHook);
|
|
68
57
|
return widget;
|
|
69
58
|
}
|
|
70
|
-
|
|
71
59
|
};
|
|
72
60
|
}
|
|
73
|
-
|
|
74
61
|
function routerAPI() {
|
|
75
62
|
return {
|
|
76
63
|
router: {
|
|
@@ -80,41 +67,33 @@ function routerAPI() {
|
|
|
80
67
|
...data
|
|
81
68
|
});
|
|
82
69
|
},
|
|
83
|
-
|
|
84
70
|
link(widget, routeName, data = {}) {
|
|
85
71
|
return widget.$dependencies.link(routeName, data);
|
|
86
72
|
},
|
|
87
|
-
|
|
88
73
|
getCurrentRoute(widget) {
|
|
89
74
|
return widget.$in.router.route;
|
|
90
75
|
}
|
|
91
|
-
|
|
92
76
|
}
|
|
93
77
|
};
|
|
94
78
|
}
|
|
95
|
-
|
|
96
79
|
async function bootstrapHook(widget, originalBootstrap, ...rest) {
|
|
97
80
|
if (widget.$in.router.isBootstrapCalled) {
|
|
98
81
|
return;
|
|
99
82
|
}
|
|
100
|
-
|
|
101
83
|
widget.$in.router.isBootstrapCalled = true;
|
|
102
84
|
return originalBootstrap(...rest);
|
|
103
|
-
}
|
|
104
|
-
|
|
85
|
+
}
|
|
105
86
|
|
|
87
|
+
// hook Component
|
|
106
88
|
async function loadHook(widget, originalLoad, ...rest) {
|
|
107
89
|
const plugin = widget.$in.router;
|
|
108
|
-
|
|
109
90
|
if (!plugin.isMounting && widget.props.pathname !== plugin.pathname) {
|
|
110
91
|
await tearDownRouterCycle(widget, ...rest);
|
|
111
92
|
await setupRouterCycle(widget, ...rest);
|
|
112
93
|
}
|
|
113
|
-
|
|
114
94
|
if (!core.isFunction(plugin.route.load)) {
|
|
115
95
|
throw new Error('The load method is mandatory.');
|
|
116
96
|
}
|
|
117
|
-
|
|
118
97
|
const globalStatePromise = core.isFunction(originalLoad) ? originalLoad(widget, ...rest) : Promise.resolve({});
|
|
119
98
|
const routeStatePromise = plugin.route.load(widget, {
|
|
120
99
|
route: plugin.route,
|
|
@@ -122,30 +101,27 @@ async function loadHook(widget, originalLoad, ...rest) {
|
|
|
122
101
|
globalState: globalStatePromise
|
|
123
102
|
});
|
|
124
103
|
const [globalState, routeState] = await Promise.all([globalStatePromise, routeStatePromise]);
|
|
125
|
-
return {
|
|
104
|
+
return {
|
|
105
|
+
...globalState,
|
|
126
106
|
...routeState
|
|
127
107
|
};
|
|
128
|
-
}
|
|
129
|
-
|
|
108
|
+
}
|
|
130
109
|
|
|
110
|
+
// hook Component
|
|
131
111
|
async function mountHook(widget, originalMount, ...rest) {
|
|
132
112
|
await widget.bootstrap(...rest);
|
|
133
113
|
const plugin = widget.$in.router;
|
|
134
|
-
|
|
135
114
|
if (!plugin.route) {
|
|
136
115
|
await resolveRoute(widget);
|
|
137
116
|
plugin.isMounting = true;
|
|
138
117
|
}
|
|
139
|
-
|
|
140
118
|
const result = await originalMount(...rest);
|
|
141
|
-
|
|
142
119
|
if (plugin.isMounting && core.isFunction(plugin.route.init)) {
|
|
143
120
|
await plugin.route.init(widget, {
|
|
144
121
|
route: plugin.route,
|
|
145
122
|
args: rest
|
|
146
123
|
});
|
|
147
124
|
}
|
|
148
|
-
|
|
149
125
|
if (core.isFunction(plugin.route.activate) && isClient() && !plugin.isRouteActivated) {
|
|
150
126
|
plugin.isRouteActivated = true;
|
|
151
127
|
plugin.route.activate(widget, {
|
|
@@ -153,16 +129,14 @@ async function mountHook(widget, originalMount, ...rest) {
|
|
|
153
129
|
args: rest
|
|
154
130
|
});
|
|
155
131
|
}
|
|
156
|
-
|
|
157
132
|
plugin.isMounting = false;
|
|
158
133
|
return result;
|
|
159
|
-
}
|
|
160
|
-
|
|
134
|
+
}
|
|
161
135
|
|
|
136
|
+
// hook Component
|
|
162
137
|
async function updateHook(widget, originalUpdate, ...rest) {
|
|
163
138
|
const result = await originalUpdate(...rest);
|
|
164
139
|
const plugin = widget.$in.router;
|
|
165
|
-
|
|
166
140
|
if (core.isFunction(plugin.route.activate) && isClient() && !plugin.isRouteActivated) {
|
|
167
141
|
plugin.isRouteActivated = true;
|
|
168
142
|
plugin.route.activate(widget, {
|
|
@@ -170,28 +144,24 @@ async function updateHook(widget, originalUpdate, ...rest) {
|
|
|
170
144
|
args: rest
|
|
171
145
|
});
|
|
172
146
|
}
|
|
173
|
-
|
|
174
147
|
return result;
|
|
175
|
-
}
|
|
176
|
-
|
|
148
|
+
}
|
|
177
149
|
|
|
150
|
+
// hook Component
|
|
178
151
|
async function unmountHook(widget, originalUnmount, ...rest) {
|
|
179
152
|
const result = await originalUnmount(...rest);
|
|
180
153
|
await tearDownRouterCycle(widget, ...rest);
|
|
181
154
|
return result;
|
|
182
155
|
}
|
|
183
|
-
|
|
184
156
|
async function resolveRoute(widget) {
|
|
185
157
|
if (ENV === DEV) {
|
|
186
158
|
if (!widget.props.pathname) {
|
|
187
159
|
throw new Error('The props pathname is not defined.');
|
|
188
160
|
}
|
|
189
|
-
|
|
190
161
|
if (!widget.$dependencies.router) {
|
|
191
162
|
throw new Error('You must add calling of createRouter(widget, routes, options) to widget.setup method.');
|
|
192
163
|
}
|
|
193
164
|
}
|
|
194
|
-
|
|
195
165
|
const route = await widget.$dependencies.router.resolve({
|
|
196
166
|
pathname: widget.props.pathname,
|
|
197
167
|
widget
|
|
@@ -200,10 +170,8 @@ async function resolveRoute(widget) {
|
|
|
200
170
|
widget.$in.router.pathname = widget.props.pathname;
|
|
201
171
|
return route;
|
|
202
172
|
}
|
|
203
|
-
|
|
204
173
|
async function setupRouterCycle(widget, ...rest) {
|
|
205
174
|
const route = await resolveRoute(widget);
|
|
206
|
-
|
|
207
175
|
if (core.isFunction(route.init)) {
|
|
208
176
|
await route.init(widget, {
|
|
209
177
|
route,
|
|
@@ -211,14 +179,12 @@ async function setupRouterCycle(widget, ...rest) {
|
|
|
211
179
|
});
|
|
212
180
|
}
|
|
213
181
|
}
|
|
214
|
-
|
|
215
182
|
async function tearDownRouterCycle(widget, ...rest) {
|
|
216
183
|
const plugin = widget.$in.router;
|
|
217
184
|
const {
|
|
218
185
|
route,
|
|
219
186
|
isRouteActivated
|
|
220
187
|
} = plugin;
|
|
221
|
-
|
|
222
188
|
if (route) {
|
|
223
189
|
if (core.isFunction(route.deactivate) && isRouteActivated === true) {
|
|
224
190
|
await route.deactivate(widget, {
|
|
@@ -226,7 +192,6 @@ async function tearDownRouterCycle(widget, ...rest) {
|
|
|
226
192
|
args: rest
|
|
227
193
|
});
|
|
228
194
|
}
|
|
229
|
-
|
|
230
195
|
if (core.isFunction(route.destroy)) {
|
|
231
196
|
await route.destroy(widget, {
|
|
232
197
|
route,
|
|
@@ -234,13 +199,10 @@ async function tearDownRouterCycle(widget, ...rest) {
|
|
|
234
199
|
});
|
|
235
200
|
}
|
|
236
201
|
}
|
|
237
|
-
|
|
238
202
|
plugin.isRouteActivated = false;
|
|
239
203
|
}
|
|
240
|
-
|
|
241
204
|
function isClient() {
|
|
242
205
|
return typeof window !== 'undefined';
|
|
243
206
|
}
|
|
244
|
-
|
|
245
207
|
exports.createRouter = createRouter;
|
|
246
208
|
exports.routerPlugin = routerPlugin;
|
package/lib/index.es9.mjs
CHANGED
|
@@ -6,16 +6,15 @@ var RouterEvents = Object.freeze({
|
|
|
6
6
|
});
|
|
7
7
|
const DEV = 'development';
|
|
8
8
|
const ENV = typeof process !== 'undefined' && process && process.env ? process.env.NODE_ENV : DEV;
|
|
9
|
-
|
|
10
9
|
function createRouter(widget, routes, options) {
|
|
11
10
|
widget.$dependencies.router = new UniversalRouter(routes, options);
|
|
12
11
|
widget.$dependencies.link = generateUrls(widget.$dependencies.router);
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
function routerPlugin() {
|
|
16
14
|
return {
|
|
17
15
|
async setup(widget) {
|
|
18
|
-
widget = {
|
|
16
|
+
widget = {
|
|
17
|
+
...routerAPI(),
|
|
19
18
|
...widget
|
|
20
19
|
};
|
|
21
20
|
widget.$in.router = {
|
|
@@ -28,18 +27,15 @@ function routerPlugin() {
|
|
|
28
27
|
bindWidgetToFunctions(widget, widget.router);
|
|
29
28
|
return widget;
|
|
30
29
|
},
|
|
31
|
-
|
|
32
30
|
async create(widget) {
|
|
33
31
|
if (ENV === DEV) {
|
|
34
32
|
if (!widget.$in.component) {
|
|
35
33
|
throw new Error('You must install missing plugin: npm i @merkur/plugin-component');
|
|
36
34
|
}
|
|
37
|
-
|
|
38
35
|
if (!widget.$in.eventEmitter) {
|
|
39
36
|
throw new Error('You must install missing plugin: npm i @merkur/plugin-event-emitter');
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
|
-
|
|
43
39
|
widget.$in.component.lifeCycle = setDefaultValueForUndefined(widget.$in.component.lifeCycle, ['load'], () => {});
|
|
44
40
|
hookMethod(widget, '$in.component.lifeCycle.load', loadHook);
|
|
45
41
|
hookMethod(widget, 'bootstrap', bootstrapHook);
|
|
@@ -48,10 +44,8 @@ function routerPlugin() {
|
|
|
48
44
|
hookMethod(widget, 'update', updateHook);
|
|
49
45
|
return widget;
|
|
50
46
|
}
|
|
51
|
-
|
|
52
47
|
};
|
|
53
48
|
}
|
|
54
|
-
|
|
55
49
|
function routerAPI() {
|
|
56
50
|
return {
|
|
57
51
|
router: {
|
|
@@ -61,41 +55,33 @@ function routerAPI() {
|
|
|
61
55
|
...data
|
|
62
56
|
});
|
|
63
57
|
},
|
|
64
|
-
|
|
65
58
|
link(widget, routeName, data = {}) {
|
|
66
59
|
return widget.$dependencies.link(routeName, data);
|
|
67
60
|
},
|
|
68
|
-
|
|
69
61
|
getCurrentRoute(widget) {
|
|
70
62
|
return widget.$in.router.route;
|
|
71
63
|
}
|
|
72
|
-
|
|
73
64
|
}
|
|
74
65
|
};
|
|
75
66
|
}
|
|
76
|
-
|
|
77
67
|
async function bootstrapHook(widget, originalBootstrap, ...rest) {
|
|
78
68
|
if (widget.$in.router.isBootstrapCalled) {
|
|
79
69
|
return;
|
|
80
70
|
}
|
|
81
|
-
|
|
82
71
|
widget.$in.router.isBootstrapCalled = true;
|
|
83
72
|
return originalBootstrap(...rest);
|
|
84
|
-
}
|
|
85
|
-
|
|
73
|
+
}
|
|
86
74
|
|
|
75
|
+
// hook Component
|
|
87
76
|
async function loadHook(widget, originalLoad, ...rest) {
|
|
88
77
|
const plugin = widget.$in.router;
|
|
89
|
-
|
|
90
78
|
if (!plugin.isMounting && widget.props.pathname !== plugin.pathname) {
|
|
91
79
|
await tearDownRouterCycle(widget, ...rest);
|
|
92
80
|
await setupRouterCycle(widget, ...rest);
|
|
93
81
|
}
|
|
94
|
-
|
|
95
82
|
if (!isFunction(plugin.route.load)) {
|
|
96
83
|
throw new Error('The load method is mandatory.');
|
|
97
84
|
}
|
|
98
|
-
|
|
99
85
|
const globalStatePromise = isFunction(originalLoad) ? originalLoad(widget, ...rest) : Promise.resolve({});
|
|
100
86
|
const routeStatePromise = plugin.route.load(widget, {
|
|
101
87
|
route: plugin.route,
|
|
@@ -103,30 +89,27 @@ async function loadHook(widget, originalLoad, ...rest) {
|
|
|
103
89
|
globalState: globalStatePromise
|
|
104
90
|
});
|
|
105
91
|
const [globalState, routeState] = await Promise.all([globalStatePromise, routeStatePromise]);
|
|
106
|
-
return {
|
|
92
|
+
return {
|
|
93
|
+
...globalState,
|
|
107
94
|
...routeState
|
|
108
95
|
};
|
|
109
|
-
}
|
|
110
|
-
|
|
96
|
+
}
|
|
111
97
|
|
|
98
|
+
// hook Component
|
|
112
99
|
async function mountHook(widget, originalMount, ...rest) {
|
|
113
100
|
await widget.bootstrap(...rest);
|
|
114
101
|
const plugin = widget.$in.router;
|
|
115
|
-
|
|
116
102
|
if (!plugin.route) {
|
|
117
103
|
await resolveRoute(widget);
|
|
118
104
|
plugin.isMounting = true;
|
|
119
105
|
}
|
|
120
|
-
|
|
121
106
|
const result = await originalMount(...rest);
|
|
122
|
-
|
|
123
107
|
if (plugin.isMounting && isFunction(plugin.route.init)) {
|
|
124
108
|
await plugin.route.init(widget, {
|
|
125
109
|
route: plugin.route,
|
|
126
110
|
args: rest
|
|
127
111
|
});
|
|
128
112
|
}
|
|
129
|
-
|
|
130
113
|
if (isFunction(plugin.route.activate) && isClient() && !plugin.isRouteActivated) {
|
|
131
114
|
plugin.isRouteActivated = true;
|
|
132
115
|
plugin.route.activate(widget, {
|
|
@@ -134,16 +117,14 @@ async function mountHook(widget, originalMount, ...rest) {
|
|
|
134
117
|
args: rest
|
|
135
118
|
});
|
|
136
119
|
}
|
|
137
|
-
|
|
138
120
|
plugin.isMounting = false;
|
|
139
121
|
return result;
|
|
140
|
-
}
|
|
141
|
-
|
|
122
|
+
}
|
|
142
123
|
|
|
124
|
+
// hook Component
|
|
143
125
|
async function updateHook(widget, originalUpdate, ...rest) {
|
|
144
126
|
const result = await originalUpdate(...rest);
|
|
145
127
|
const plugin = widget.$in.router;
|
|
146
|
-
|
|
147
128
|
if (isFunction(plugin.route.activate) && isClient() && !plugin.isRouteActivated) {
|
|
148
129
|
plugin.isRouteActivated = true;
|
|
149
130
|
plugin.route.activate(widget, {
|
|
@@ -151,28 +132,24 @@ async function updateHook(widget, originalUpdate, ...rest) {
|
|
|
151
132
|
args: rest
|
|
152
133
|
});
|
|
153
134
|
}
|
|
154
|
-
|
|
155
135
|
return result;
|
|
156
|
-
}
|
|
157
|
-
|
|
136
|
+
}
|
|
158
137
|
|
|
138
|
+
// hook Component
|
|
159
139
|
async function unmountHook(widget, originalUnmount, ...rest) {
|
|
160
140
|
const result = await originalUnmount(...rest);
|
|
161
141
|
await tearDownRouterCycle(widget, ...rest);
|
|
162
142
|
return result;
|
|
163
143
|
}
|
|
164
|
-
|
|
165
144
|
async function resolveRoute(widget) {
|
|
166
145
|
if (ENV === DEV) {
|
|
167
146
|
if (!widget.props.pathname) {
|
|
168
147
|
throw new Error('The props pathname is not defined.');
|
|
169
148
|
}
|
|
170
|
-
|
|
171
149
|
if (!widget.$dependencies.router) {
|
|
172
150
|
throw new Error('You must add calling of createRouter(widget, routes, options) to widget.setup method.');
|
|
173
151
|
}
|
|
174
152
|
}
|
|
175
|
-
|
|
176
153
|
const route = await widget.$dependencies.router.resolve({
|
|
177
154
|
pathname: widget.props.pathname,
|
|
178
155
|
widget
|
|
@@ -181,10 +158,8 @@ async function resolveRoute(widget) {
|
|
|
181
158
|
widget.$in.router.pathname = widget.props.pathname;
|
|
182
159
|
return route;
|
|
183
160
|
}
|
|
184
|
-
|
|
185
161
|
async function setupRouterCycle(widget, ...rest) {
|
|
186
162
|
const route = await resolveRoute(widget);
|
|
187
|
-
|
|
188
163
|
if (isFunction(route.init)) {
|
|
189
164
|
await route.init(widget, {
|
|
190
165
|
route,
|
|
@@ -192,14 +167,12 @@ async function setupRouterCycle(widget, ...rest) {
|
|
|
192
167
|
});
|
|
193
168
|
}
|
|
194
169
|
}
|
|
195
|
-
|
|
196
170
|
async function tearDownRouterCycle(widget, ...rest) {
|
|
197
171
|
const plugin = widget.$in.router;
|
|
198
172
|
const {
|
|
199
173
|
route,
|
|
200
174
|
isRouteActivated
|
|
201
175
|
} = plugin;
|
|
202
|
-
|
|
203
176
|
if (route) {
|
|
204
177
|
if (isFunction(route.deactivate) && isRouteActivated === true) {
|
|
205
178
|
await route.deactivate(widget, {
|
|
@@ -207,7 +180,6 @@ async function tearDownRouterCycle(widget, ...rest) {
|
|
|
207
180
|
args: rest
|
|
208
181
|
});
|
|
209
182
|
}
|
|
210
|
-
|
|
211
183
|
if (isFunction(route.destroy)) {
|
|
212
184
|
await route.destroy(widget, {
|
|
213
185
|
route,
|
|
@@ -215,12 +187,9 @@ async function tearDownRouterCycle(widget, ...rest) {
|
|
|
215
187
|
});
|
|
216
188
|
}
|
|
217
189
|
}
|
|
218
|
-
|
|
219
190
|
plugin.isRouteActivated = false;
|
|
220
191
|
}
|
|
221
|
-
|
|
222
192
|
function isClient() {
|
|
223
193
|
return typeof window !== 'undefined';
|
|
224
194
|
}
|
|
225
|
-
|
|
226
195
|
export { createRouter, routerPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkur/plugin-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "Merkur router plugin.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"module": "lib/index",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
},
|
|
57
57
|
"homepage": "https://merkur.js.org/",
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@merkur/core": "^0.
|
|
60
|
-
"@merkur/plugin-component": "^0.
|
|
61
|
-
"@merkur/plugin-event-emitter": "^0.
|
|
59
|
+
"@merkur/core": "^0.30.0",
|
|
60
|
+
"@merkur/plugin-component": "^0.30.0",
|
|
61
|
+
"@merkur/plugin-event-emitter": "^0.30.0",
|
|
62
62
|
"rollup": "^2.70.2"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"universal-router": "^9.1.0"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "13a0ac12f77f381b1d829cffe9b21d453c26ca7a"
|
|
73
73
|
}
|