yuzu-application
Version:
Yuzu Application Manager
3 lines (2 loc) • 4.42 kB
JavaScript
"use strict";var t,e=(t=require("tiny-invariant"))&&"object"==typeof t&&"default"in t?t.default:t,r=require("yuzu-utils"),n=require("yuzu");function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function i(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var s=function(t){void 0===t&&(t={});var e=t;return{getData:function(){return o({},e)},update:function(t){e=o({},t)},inject:function(t){var e=this;return Object.defineProperty(t,"$context",{enumerable:!1,get:function(){return e.getData()}})}}},c=r.createSequence(),a=r.createSequence(),u=function(t){var u,f;function l(e){var r;void 0===e&&(e={}),(r=t.call(this,e)||this).$registry=[],r.$instances=new Map;var n=r.options,s=n.components,a=void 0===s?[]:s;return r.$id=n.id||c("_sbx-"),a.forEach((function(t){if(Array.isArray(t)){var e=t[0],n=t[1],i=void 0===n?{}:n,s=e.root||i.selector;s&&r.register(o({component:e,selector:s},i))}else t.root&&r.register({component:t,selector:t.root})})),i(r)||i(r)}f=t,(u=l).prototype=Object.create(f.prototype),u.prototype.constructor=u,u.__proto__=f;var h=l.prototype;return h.defaultOptions=function(){return{components:[],context:s(),id:"",root:document.body}},h.register=function(t){n.Component.isComponent(t.component)||e(!1),"string"!=typeof t.selector&&"function"!=typeof t.selector&&e(!1),this.$registry.push(t)},h.start=function(t){return void 0===t&&(t={}),Object.defineProperty(this,"$legacyStart",{value:!0}),this.mount(this.options.root),this.setup(),this.$ctx&&this.$ctx.update(t),this.discover(),this},h.mount=function(e,r){return void 0===r&&(r={}),t.prototype.mount.call(this,e,r),this.$el.setAttribute(l.SB_DATA_ATTR,""),this.hasOwnProperty("$legacyStart")||(this.setup(),this.discover()),this},h.setup=function(){this.$ctx=this.options.context,this.$ctx.inject(this)},h.discover=function(){var t=this,n=this;r.isElement(this.$el)||e(!1),this.emit("beforeStart");var o="["+l.SB_DATA_ATTR+"]",i=this.$registry.map((function(t){var e=t.component,i=t.selector,s=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}(t,["component","selector"]);try{if(n.$instances.has(i))return n.$warn("Component "+e+" already initialized on "+i),Promise.resolve();var c,a=n.resolveSelector(i);if(!0===a)c=[n.createInstance(e,s)];else if(Array.isArray(a)){var u=n.$el;c=a.filter((function(t){return r.isElement(t)&&!t.dataset.skip&&!t.closest("[data-skip]")&&t.closest(o)===u})).map((function(t){return n.createInstance(e,s,t)}))}var f=function(){if(c){var t=n.$instances,e=t.set;return Promise.resolve(Promise.all(c)).then((function(r){e.call(t,i,r)}))}}();return Promise.resolve(!f||!f.then||f.then((function(){return!0})))}catch(t){return Promise.reject(t)}}));return Promise.all(i).then((function(){t.emit("start")}))},h.resolveSelector=function(t){var e=r.evaluate(t,this);return"string"==typeof e&&(e=this.findNodes(e)),e},h.createInstance=function(t,e,n){var i=n?r.datasetParser(n):{};return this.setRef(o({id:a(this.$id+"-c.")},e,{},i,{component:t,el:n}))},h.stop=function(){try{return Promise.resolve(this.destroy())}catch(t){return Promise.reject(t)}},h.destroy=function(){try{var e=this;return e.emit("beforeStop"),Promise.resolve(e.beforeDestroy()).then((function(){var r=!1;function n(n){return r?n:(e.$instances.clear(),e.emit("stop"),e.clear(),t.prototype.destroy.call(e))}e.removeListeners();var o=function(t,r){try{var n=(e.$el&&e.$el.removeAttribute(l.SB_DATA_ATTR),Promise.resolve(e.destroyRefs()).then((function(){e.$active=!1})))}catch(t){return r(t)}return n&&n.then?n.then(void 0,r):n}(0,(function(t){return e.emit("error",t),r=!0,Promise.reject(t)}));return o&&o.then?o.then(n):n(o)}))}catch(t){return Promise.reject(t)}},h.clear=function(){this.$ctx=void 0,this.off("beforeStart"),this.off("start"),this.off("error"),this.off("beforeStop"),this.off("stop")},l}(n.Component);u.SB_DATA_ATTR="data-yuzu-sb",exports.Sandbox=u,exports.createContext=s;
//# sourceMappingURL=yuzu-application.cjs.production.min.js.map