react-controlled-dialog
Version:
A declarative interface for the native dialog element
6 lines • 11.7 kB
JavaScript
module.exports=function(e){var n={};function r(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)r.d(t,o,function(n){return e[n]}.bind(null,o));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=7)}([function(e,n,r){var t="function"==typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103;e.exports=r(3)(function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},!0)},function(e,n){e.exports=require("react")},function(e,n,r){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,n,r){"use strict";var t=r(4),o=r(2),i=r(5),a=function(){};function u(){return null}a=function(e){var n="Warning: "+e;"undefined"!=typeof console&&console.error(n);try{throw new Error(n)}catch(e){}},e.exports=function(e,n){var r="function"==typeof Symbol&&Symbol.iterator,c="@@iterator";var f="<<anonymous>>",l={array:d("array"),bool:d("boolean"),func:d("function"),number:d("number"),object:d("object"),string:d("string"),symbol:d("symbol"),any:y(u),arrayOf:function(e){return y(function(n,r,t,i,a){if("function"!=typeof e)return new p("Property `"+a+"` of component `"+t+"` has invalid PropType notation inside arrayOf.");var u=n[r];if(!Array.isArray(u)){var c=b(u);return new p("Invalid "+i+" `"+a+"` of type `"+c+"` supplied to `"+t+"`, expected an array.")}for(var f=0;f<u.length;f++){var l=e(u,f,t,i,a+"["+f+"]",o);if(l instanceof Error)return l}return null})},element:function(){return y(function(n,r,t,o,i){var a=n[r];if(!e(a)){var u=b(a);return new p("Invalid "+o+" `"+i+"` of type `"+u+"` supplied to `"+t+"`, expected a single ReactElement.")}return null})}(),instanceOf:function(e){return y(function(n,r,t,o,i){if(!(n[r]instanceof e)){var a=e.name||f,u=function(e){if(!e.constructor||!e.constructor.name)return f;return e.constructor.name}(n[r]);return new p("Invalid "+o+" `"+i+"` of type `"+u+"` supplied to `"+t+"`, expected instance of `"+a+"`.")}return null})},node:function(){return y(function(e,n,r,t,o){if(!v(e[n]))return new p("Invalid "+t+" `"+o+"` supplied to `"+r+"`, expected a ReactNode.");return null})}(),objectOf:function(e){return y(function(n,r,t,i,a){if("function"!=typeof e)return new p("Property `"+a+"` of component `"+t+"` has invalid PropType notation inside objectOf.");var u=n[r],c=b(u);if("object"!==c)return new p("Invalid "+i+" `"+a+"` of type `"+c+"` supplied to `"+t+"`, expected an object.");for(var f in u)if(u.hasOwnProperty(f)){var l=e(u,f,t,i,a+"."+f,o);if(l instanceof Error)return l}return null})},oneOf:function(e){if(!Array.isArray(e))return a("Invalid argument supplied to oneOf, expected an instance of array."),u;return y(function(n,r,t,o,i){for(var a=n[r],u=0;u<e.length;u++)if(s(a,e[u]))return null;var c=JSON.stringify(e);return new p("Invalid "+o+" `"+i+"` of value `"+a+"` supplied to `"+t+"`, expected one of "+c+".")})},oneOfType:function(e){if(!Array.isArray(e))return a("Invalid argument supplied to oneOfType, expected an instance of array."),u;for(var n=0;n<e.length;n++){var r=e[n];if("function"!=typeof r)return a("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+g(r)+" at index "+n+"."),u}return y(function(n,r,t,i,a){for(var u=0;u<e.length;u++){var c=e[u];if(null==c(n,r,t,i,a,o))return null}return new p("Invalid "+i+" `"+a+"` supplied to `"+t+"`.")})},shape:function(e){return y(function(n,r,t,i,a){var u=n[r],c=b(u);if("object"!==c)return new p("Invalid "+i+" `"+a+"` of type `"+c+"` supplied to `"+t+"`, expected `object`.");for(var f in e){var l=e[f];if(l){var s=l(u,f,t,i,a+"."+f,o);if(s)return s}}return null})},exact:function(e){return y(function(n,r,i,a,u){var c=n[r],f=b(c);if("object"!==f)return new p("Invalid "+a+" `"+u+"` of type `"+f+"` supplied to `"+i+"`, expected `object`.");var l=t({},n[r],e);for(var s in l){var y=e[s];if(!y)return new p("Invalid "+a+" `"+u+"` key `"+s+"` supplied to `"+i+"`.\nBad object: "+JSON.stringify(n[r],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(e),null," "));var d=y(c,s,i,a,u+"."+s,o);if(d)return d}return null})}};function s(e,n){return e===n?0!==e||1/e==1/n:e!=e&&n!=n}function p(e){this.message=e,this.stack=""}function y(e){var r={},t=0;function i(i,u,c,l,s,y,d){if(l=l||f,y=y||c,d!==o){if(n){var v=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");throw v.name="Invariant Violation",v}if("undefined"!=typeof console){var b=l+":"+c;!r[b]&&t<3&&(a("You are manually calling a React.PropTypes validation function for the `"+y+"` prop on `"+l+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),r[b]=!0,t++)}}return null==u[c]?i?null===u[c]?new p("The "+s+" `"+y+"` is marked as required in `"+l+"`, but its value is `null`."):new p("The "+s+" `"+y+"` is marked as required in `"+l+"`, but its value is `undefined`."):null:e(u,c,l,s,y)}var u=i.bind(null,!1);return u.isRequired=i.bind(null,!0),u}function d(e){return y(function(n,r,t,o,i,a){var u=n[r];return b(u)!==e?new p("Invalid "+o+" `"+i+"` of type `"+m(u)+"` supplied to `"+t+"`, expected `"+e+"`."):null})}function v(n){switch(typeof n){case"number":case"string":case"undefined":return!0;case"boolean":return!n;case"object":if(Array.isArray(n))return n.every(v);if(null===n||e(n))return!0;var t=function(e){var n=e&&(r&&e[r]||e[c]);if("function"==typeof n)return n}(n);if(!t)return!1;var o,i=t.call(n);if(t!==n.entries){for(;!(o=i.next()).done;)if(!v(o.value))return!1}else for(;!(o=i.next()).done;){var a=o.value;if(a&&!v(a[1]))return!1}return!0;default:return!1}}function b(e){var n=typeof e;return Array.isArray(e)?"array":e instanceof RegExp?"object":function(e,n){return"symbol"===e||"Symbol"===n["@@toStringTag"]||"function"==typeof Symbol&&n instanceof Symbol}(n,e)?"symbol":n}function m(e){if(null==e)return""+e;var n=b(e);if("object"===n){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return n}function g(e){var n=m(e);switch(n){case"array":case"object":return"an "+n;case"boolean":case"date":case"regexp":return"a "+n;default:return n}}return p.prototype=Error.prototype,l.checkPropTypes=i,l.PropTypes=l,l}},function(e,n,r){"use strict";
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/var t=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var n={},r=0;r<10;r++)n["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(n).map(function(e){return n[e]}).join(""))return!1;var t={};return"abcdefghijklmnopqrst".split("").forEach(function(e){t[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},t)).join("")}catch(e){return!1}}()?Object.assign:function(e,n){for(var r,a,u=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(e),c=1;c<arguments.length;c++){for(var f in r=Object(arguments[c]))o.call(r,f)&&(u[f]=r[f]);if(t){a=t(r);for(var l=0;l<a.length;l++)i.call(r,a[l])&&(u[a[l]]=r[a[l]])}}return u}},function(e,n,r){"use strict";var t=function(){},o=r(2),i={};t=function(e){var n="Warning: "+e;"undefined"!=typeof console&&console.error(n);try{throw new Error(n)}catch(e){}},e.exports=function(e,n,r,a,u){for(var c in e)if(e.hasOwnProperty(c)){var f;try{if("function"!=typeof e[c]){var l=Error((a||"React class")+": "+r+" type `"+c+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[c]+"`.");throw l.name="Invariant Violation",l}f=e[c](n,c,a,r,null,o)}catch(e){f=e}if(!f||f instanceof Error||t((a||"React class")+": type specification of "+r+" `"+c+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof f+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),f instanceof Error&&!(f.message in i)){i[f.message]=!0;var s=u?u():"";t("Failed "+r+" type: "+f.message+(null!=s?s:""))}}}},function(e,n,r){"use strict";var t=r(2);function o(){}e.exports=function(){function e(e,n,r,o,i,a){if(a!==t){var u=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw u.name="Invariant Violation",u}}function n(){return e}e.isRequired=e;var r={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:n,element:e,instanceOf:n,node:e,objectOf:n,oneOf:n,oneOfType:n,shape:n,exact:n};return r.checkPropTypes=o,r.PropTypes=r,r}},function(e,n,r){"use strict";r.r(n);var t=r(1),o=r.n(t),i=r(0),a=r.n(i);function u(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var r=[],t=!0,o=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(t=(a=u.next()).done)&&(r.push(a.value),!n||r.length!==n);t=!0);}catch(e){o=!0,i=e}finally{try{t||null==u.return||u.return()}finally{if(o)throw i}}return r}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function c(){return(c=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e}).apply(this,arguments)}var f=function(e){var n=e.onClick;return o.a.createElement("button",{onClick:n,"aria-label":"Close"},"x")},l=o.a.forwardRef(function(e,n){return o.a.createElement("dialog",c({ref:n},e))});var s=function(e){var n,r=e.children,i=e.isOpen,a=e.setOpen,c=e.type,s=void 0===c?"dialog":c,p=e.CloseButton,y=void 0===p?f:p,d=e.DialogComponent,v=void 0===d?l:d,b=e.closeOnBackdropClick,m=void 0!==b&&b,g=e.onClick,h=o.a.createRef(),O=u(Object(t.useState)(!1),2),j=O[0],w=O[1];Object(t.useEffect)(function(){j||(window.dialogPolyfill&&window.dialogPolyfill.registerDialog(h),w(!0))}),Object(t.useEffect)(function(){if(n=h.current||{},i&&!n.open)return"modal"===s?n.showModal():n.show();!i&&n.open&&n.close()});return o.a.createElement(v,{ref:h,role:s,onClick:function(e){g&&g(),function(e){("function"==typeof m?m():m)&&!function(e){var n=e.currentTarget,r=n.getBoundingClientRect(),t=r.left+n.clientLeft,o=e.clientX;if(o<t||o>=t+n.clientWidth)return!1;var i=r.top+n.clientTop,a=e.clientY;return!(a<i||a>=i+n.clientHeight)}(e)&&n.close()}(e)}},o.a.createElement(y,{onClick:function(){return a(!1)},"aria-label":"Close"}),r)};s.propTypes={isOpen:i.bool.isRequired,setOpen:i.func.isRequired,children:Object(i.oneOfType)([Object(i.arrayOf)(i.node),i.node]),type:Object(i.oneOf)(["dialog","modal"]),closeOnBackdropClick:i.bool||i.func,DialogComponent:a.a.oneOfType([a.a.string,a.a.func,a.a.object]),closeButton:i.node,onClick:i.func};var p=s;n.default=p}]);