2 lines
8.3 KiB
JavaScript
2 lines
8.3 KiB
JavaScript
(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports,require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-dom"],b):(a=a||self,b(a.Remount={},a.React,a.ReactDOM))})(this,function(a,b,c){"use strict";function d(a){return d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},d(a)}function e(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function f(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function g(a,b,c){return b&&f(a.prototype,b),c&&f(a,c),a}function h(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&j(a,b)}function i(a){return i=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},i(a)}function j(a,b){return j=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},j(a,b)}function k(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(a){return!1}}function l(){return l=k()?Reflect.construct:function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&j(f,d.prototype),f},l.apply(null,arguments)}function m(a){return-1!==Function.toString.call(a).indexOf("[native code]")}function n(a){var b="function"==typeof Map?new Map:void 0;return n=function(a){function c(){return l(a,arguments,i(this).constructor)}if(null===a||!m(a))return a;if("function"!=typeof a)throw new TypeError("Super expression must either be null or a function");if("undefined"!=typeof b){if(b.has(a))return b.get(a);b.set(a,c)}return c.prototype=Object.create(a.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),j(c,a)},n(a)}function o(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function p(a,b){return b&&("object"==typeof b||"function"==typeof b)?b:o(a)}function q(a){return r(a)||s(a)||t()}function r(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function s(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function t(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function u(){if(!(window.HTMLElement&&window.HTMLElement._babelES5Adapter||void 0===window.Reflect||void 0===window.customElements||window.customElements.hasOwnProperty("polyfillWrapFlushCallback"))){var b=HTMLElement;window.HTMLElement=function(){return Reflect.construct(b,[],this.constructor)},HTMLElement.prototype=b.prototype,HTMLElement.prototype.constructor=HTMLElement,Object.setPrototypeOf(HTMLElement,b),HTMLElement._babelES5Adapter=!0}}function v(a,b,c){var d=c.onUpdate,f=c.onUnmount,j=c.onMount;u();var k=a.attributes||[],l=function(b){function c(){return e(this,c),p(this,i(c).apply(this,arguments))}return h(c,b),g(c,[{key:"connectedCallback",value:function(){this._mountPoint=w(this,a),j(this,this._mountPoint)}},{key:"disconnectedCallback",value:function(){this._mountPoint&&f(this,this._mountPoint)}},{key:"attributeChangedCallback",value:function(){this._mountPoint&&d(this,this._mountPoint)}}],[{key:"observedAttributes",get:function(){return["props-json"].concat(q(k))}}]),c}(n(HTMLElement));a.quiet&&window.customElements.get(b)||window.customElements.define(b,l)}function w(a,b){var c=b.shadow;if(c&&a.attachShadow){var d=document.createElement("span");return a.attachShadow({mode:"open"}).appendChild(d),d}return a}function x(a,b){for(var c=0,d=a.length;c<d;c++)b(a[c])}function y(){return"MutationObserver"in window}function z(a,b,c){a.nodeName.toLowerCase()===b?(c.onMount(a,a),A(a,c),B(a,c)):a.children&&a.children.length&&x(a.children,function(a){D(a)&&z(a,b,c)})}function A(a,b){var c=b.onUpdate,d=new MutationObserver(function(a){x(a,function(a){var b=a.target;D(b)&&c(b,b)})});d.observe(a,{attributes:!0})}function B(a,b){var c=b.onUnmount,d=a.parentNode;if(d){var e=new MutationObserver(function(b){x(b,function(b){x(b.removedNodes,function(b){a!==b||D(a)&&(e.disconnect(d),c(a,a))})})});e.observe(d,{childList:!0,subtree:!0})}}function C(a){return!!(-1!==a.indexOf("-")&&a.match(/^[a-z][a-z0-9-]*$/))}function D(a){return!!a}function E(a){for(var b in a)if(a.hasOwnProperty(b)&&-1!==b.indexOf("_reactInternal"))return a[b]}function F(a){return a?a.memoizedProps?a.memoizedProps:a._currentElement&&a._currentElement.props?a._currentElement.props:void 0:void 0}function G(a,b,c){c[b]&&c[b](a)}function H(a){return T[a]?T[a]:a.replace(/^on/,"").toLowerCase()}function I(a){for(var b=[];a;){if(b.push(a),"HTML"===a.tagName)return b.push(document),b.push(window),b;a=a.parentElement}}function J(a,d,e,f){var g=a.component,h=b.createElement(g,e);c.render(h,d),f&&V(f.shadowRoot)}function K(){if(O)return O;var a=[P,R].find(function(a){return!!a.isSupported()});return a||console.warn("Remount: This browser doesn't support the MutationObserver API or the Custom Elements API. Including polyfills might fix this. Remount elements will not work. https://github.com/rstacruz/remount"),O=a,a}function L(a){return M(a)?a:{component:a}}function M(a){return"object"===d(a)&&a.component}function N(a,b){var c=a.getAttribute("props-json");if(c)return JSON.parse(c);return(b||[]).reduce(function(b,c){return b[c]=a.getAttribute(c),b},{})}var O,P=Object.freeze({name:"CustomElements",defineElement:v,isSupported:function(){return!!(window.customElements&&window.customElements.define)},supportsShadow:function(){return!!(document&&document.body&&document.body.attachShadow)}}),Q={},R=Object.freeze({name:"MutationObserver",observers:Q,isSupported:y,defineElement:function(a,b,c){if(b=b.toLowerCase(),!C(b)){if(a.quiet)return;throw new Error("Remount: \"".concat(b,"\" is not a valid custom element elName"))}if(Q[b]){if(a.quiet)return;throw new Error("Remount: \"".concat(b,"\" is already registered"))}var d=new MutationObserver(function(a){x(a,function(a){x(a.addedNodes,function(a){D(a)&&z(a,b,c)})})});d.observe(document.body,{childList:!0,subtree:!0}),Q.MutationObserver=d,window.addEventListener("DOMContentLoaded",function(){var a=document.getElementsByTagName("MutationObserver");x(a,function(a){return z(a,"MutationObserver",c)})})},supportsShadow:function(){return!1}}),S=["onAbort","onAnimationCancel","onAnimationEnd","onAnimationIteration","onAuxClick","onBlur","onChange","onClick","onClose","onContextMenu","onDoubleClick","onError","onFocus","onGotPointerCapture","onInput","onKeyDown","onKeyPress","onKeyUp","onLoad","onLoadEnd","onLoadStart","onLostPointerCapture","onMouseDown","onMouseMove","onMouseOut","onMouseOver","onMouseUp","onPointerCancel","onPointerDown","onPointerEnter","onPointerLeave","onPointerMove","onPointerOut","onPointerOver","onPointerUp","onReset","onResize","onScroll","onSelect","onSelectionChange","onSelectStart","onSubmit","onTouchCancel","onTouchMove","onTouchStart","onTransitionCancel","onTransitionEnd","onDrag","onDragEnd","onDragEnter","onDragExit","onDragLeave","onDragOver","onDragStart","onDrop","onFocusOut"],T={onDoubleClick:"dblclick"},U={onInput:"onChange",onFocusOut:"onBlur",onSelectionChange:"onSelect"},V=function(a){S.forEach(function(b){var c=H(b);a.addEventListener(c,function(c){for(var d=c.path||c.composedPath&&c.composedPath()||I(c.target),e=0;e<d.length;e++){var f=d[e],g=E(f),h=F(g);if(g&&h&&G(c,b,h),g&&h&&U[b]&&G(c,U[b],h),c.cancelBubble)break;if(f===a)break}},!1)})},W=Object.freeze({mount:function(a,b,c,d){return J(a,b,c,d)},update:J,unmount:function(a,b){c.unmountComponentAtNode(b)}});a.getStrategy=K,a.define=function(a,b){var c=K();c&&Object.keys(a).forEach(function(d){var e=Object.assign({},b,L(a[d])),f=e.adapter||W;c.defineElement(e,d,{onMount:function(a,b){var c=N(a,e.attributes);e.shadow&&e.retarget?f.mount(e,b,c,a):f.mount(e,b,c,null)},onUpdate:function(a,b){var c=N(a,e.attributes);f.update(e,b,c,null)},onUnmount:function(a,b){f.unmount(e,b)}})})},Object.defineProperty(a,"__esModule",{value:!0})});
|