@humanmade/react-slot-fill
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,32 +0,2 @@ | ||
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"T5Ac":[function(require,module,exports) { | ||
module.exports=require('react'); | ||
},{}],"u5no":[function(require,module,exports) { | ||
module.exports=require('lodash'); | ||
},{}],"Cej4":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isEmptyElement=void 0;var e=require("lodash"),r=function(r){return!(0,e.isNumber)(r)&&((0,e.isString)(r)||(0,e.isArray)(r)?!r.length:!r)};exports.isEmptyElement=r; | ||
},{"lodash":"u5no"}],"W9Wi":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var e=require("react"),t=(0,e.createContext)({slots:{},fills:{},registerSlot:function(){},unregisterSlot:function(){},registerFill:function(){},unregisterFill:function(){}}),r=t;exports.default=r; | ||
},{"react":"T5Ac"}],"e9O0":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=w;var t=o(require("react")),r=e(require("./slot-fill-context"));function e(t){return t&&t.__esModule?t:{default:t}}function n(){if("function"!=typeof WeakMap)return null;var t=new WeakMap;return n=function(){return t},t}function o(t){if(t&&t.__esModule)return t;if(null===t||"object"!=typeof t&&"function"!=typeof t)return{default:t};var r=n();if(r&&r.has(t))return r.get(t);var e={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in t)if(Object.prototype.hasOwnProperty.call(t,u)){var i=o?Object.getOwnPropertyDescriptor(t,u):null;i&&(i.get||i.set)?Object.defineProperty(e,u,i):e[u]=t[u]}return e.default=t,r&&r.set(t,e),e}function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t){return c(t)||f(t)||j(t)||l()}function l(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function f(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}function c(t){if(Array.isArray(t))return g(t)}function a(t,r){if(null==t)return{};var e,n,o=y(t,r);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(t);for(n=0;n<u.length;n++)e=u[n],r.indexOf(e)>=0||Object.prototype.propertyIsEnumerable.call(t,e)&&(o[e]=t[e])}return o}function y(t,r){if(null==t)return{};var e,n,o={},u=Object.keys(t);for(n=0;n<u.length;n++)e=u[n],r.indexOf(e)>=0||(o[e]=t[e]);return o}function s(t){var r=b(t,"string");return"symbol"===u(r)?r:String(r)}function b(t,r){if("object"!==u(t)||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!==u(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function p(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable})),e.push.apply(e,n)}return e}function m(t){for(var r=1;r<arguments.length;r++){var e=null!=arguments[r]?arguments[r]:{};r%2?p(Object(e),!0).forEach(function(r){v(t,r,e[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):p(Object(e)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))})}return t}function v(t,r,e){return r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function O(t,r){return h(t)||S(t,r)||j(t,r)||d()}function d(){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 j(t,r){if(t){if("string"==typeof t)return g(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(e):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?g(t,r):void 0}}function g(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function S(t,r){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var e=[],n=!0,o=!1,u=void 0;try{for(var i,l=t[Symbol.iterator]();!(n=(i=l.next()).done)&&(e.push(i.value),!r||e.length!==r);n=!0);}catch(f){o=!0,u=f}finally{try{n||null==l.return||l.return()}finally{if(o)throw u}}return e}}function h(t){if(Array.isArray(t))return t}function P(){var r=O((0,t.useState)({}),2),e=r[0],n=r[1],o=O((0,t.useState)({}),2),u=o[0],l=o[1],f=(0,t.useCallback)(function(t,r,e){n(function(n){return m({},n,v({},t,m({},n[t],{ref:r||n[t].ref,fillProps:e||n[t].fillProps||{}})))})},[]),c=(0,t.useCallback)(function(t,r){n(function(e){var n=e[t],o=a(e,[t].map(s));return n.ref===r?o:e})},[]),y=(0,t.useCallback)(function(t,r){l(function(e){return m({},e,v({},t,[].concat(i(e[t]||[]),[r])))})},[]),b=(0,t.useCallback)(function(t,r){l(function(e){return e[t]?m({},e,v({},t,e[t].filter(function(t){return t!==r}))):e})},[]);return(0,t.useMemo)(function(){return{slots:e,fills:u,registerSlot:f,updateSlot:f,unregisterSlot:c,registerFill:y,unregisterFill:b}},[e,u,f,c,y,b])}function w(e){var n=e.children,o=P();return t.default.createElement(r.default.Provider,{value:o},n)} | ||
},{"react":"T5Ac","./slot-fill-context":"W9Wi"}],"e4GB":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Consumer=exports.default=exports.useSlot=void 0;var t=require("lodash"),e=i(require("react")),r=n(require("./bubbles-virtually/slot-fill-provider"));function n(t){return t&&t.__esModule?t:{default:t}}function o(){if("function"!=typeof WeakMap)return null;var t=new WeakMap;return o=function(){return t},t}function i(t){if(t&&t.__esModule)return t;if(null===t||"object"!=typeof t&&"function"!=typeof t)return{default:t};var e=o();if(e&&e.has(t))return e.get(t);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var l=n?Object.getOwnPropertyDescriptor(t,i):null;l&&(l.get||l.set)?Object.defineProperty(r,i,l):r[i]=t[i]}return r.default=t,e&&e.set(t,r),r}function l(t,e){return c(t)||s(t,e)||p(t,e)||u()}function u(){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 s(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var r=[],n=!0,o=!1,i=void 0;try{for(var l,u=t[Symbol.iterator]();!(n=(l=u.next()).done)&&(r.push(l.value),!e||r.length!==e);n=!0);}catch(s){o=!0,i=s}finally{try{n||null==u.return||u.return()}finally{if(o)throw i}}return r}}function c(t){if(Array.isArray(t))return t}function f(t){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t){return h(t)||b(t)||p(t)||y()}function y(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function p(t,e){if(t){if("string"==typeof t)return g(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?g(t,e):void 0}}function b(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}function h(t){if(Array.isArray(t))return g(t)}function g(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function d(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function v(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function S(t,e,r){return e&&v(t.prototype,e),r&&v(t,r),t}function m(t){return function(){var e,r=w(t);if(j()){var n=w(this).constructor;e=Reflect.construct(r,arguments,n)}else e=r.apply(this,arguments);return F(this,e)}}function F(t,e){return!e||"object"!==f(e)&&"function"!=typeof e?O(t):e}function O(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function j(){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(t){return!1}}function w(t){return(w=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function k(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&x(t,e)}function x(t,e){return(x=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var _=(0,e.createContext)({registerSlot:function(){},unregisterSlot:function(){},registerFill:function(){},unregisterFill:function(){},getSlot:function(){},getFills:function(){},subscribe:function(){}}),P=_.Provider,E=_.Consumer;exports.Consumer=E;var A=function(n){k(i,e.Component);var o=m(i);function i(){var t;return d(this,i),(t=o.apply(this,arguments)).registerSlot=t.registerSlot.bind(O(t)),t.registerFill=t.registerFill.bind(O(t)),t.unregisterSlot=t.unregisterSlot.bind(O(t)),t.unregisterFill=t.unregisterFill.bind(O(t)),t.getSlot=t.getSlot.bind(O(t)),t.getFills=t.getFills.bind(O(t)),t.hasFills=t.hasFills.bind(O(t)),t.subscribe=t.subscribe.bind(O(t)),t.slots={},t.fills={},t.listeners=[],t.contextValue={registerSlot:t.registerSlot,unregisterSlot:t.unregisterSlot,registerFill:t.registerFill,unregisterFill:t.unregisterFill,getSlot:t.getSlot,getFills:t.getFills,hasFills:t.hasFills,subscribe:t.subscribe},t}return S(i,[{key:"registerSlot",value:function(t,e){var r=this.slots[t];this.slots[t]=e,this.triggerListeners(),this.forceUpdateSlot(t),r&&r.forceUpdate()}},{key:"registerFill",value:function(t,e){this.fills[t]=[].concat(a(this.fills[t]||[]),[e]),this.forceUpdateSlot(t)}},{key:"unregisterSlot",value:function(t,e){this.slots[t]===e&&(delete this.slots[t],this.triggerListeners())}},{key:"unregisterFill",value:function(e,r){this.fills[e]=(0,t.without)(this.fills[e],r),this.resetFillOccurrence(e),this.forceUpdateSlot(e)}},{key:"getSlot",value:function(t){return this.slots[t]}},{key:"getFills",value:function(e,r){return this.slots[e]!==r?[]:(0,t.sortBy)(this.fills[e],"occurrence")}},{key:"hasFills",value:function(t){return this.fills[t]&&!!this.fills[t].length}},{key:"resetFillOccurrence",value:function(e){(0,t.forEach)(this.fills[e],function(t){t.occurrence=void 0})}},{key:"forceUpdateSlot",value:function(t){var e=this.getSlot(t);e&&e.forceUpdate()}},{key:"triggerListeners",value:function(){this.listeners.forEach(function(t){return t()})}},{key:"subscribe",value:function(e){var r=this;return this.listeners.push(e),function(){r.listeners=(0,t.without)(r.listeners,e)}}},{key:"render",value:function(){return e.default.createElement(P,{value:this.contextValue},e.default.createElement(r.default,null,this.props.children))}}]),i}(),C=function(t){var r=(0,e.useContext)(_),n=r.getSlot,o=r.subscribe,i=l((0,e.useState)(n(t)),2),u=i[0],s=i[1];return(0,e.useEffect)(function(){return s(n(t)),o(function(){s(n(t))})},[t]),u};exports.useSlot=C;var U=A;exports.default=U; | ||
},{"lodash":"u5no","react":"T5Ac","./bubbles-virtually/slot-fill-provider":"e9O0"}],"LYME":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var e=require("lodash"),t=i(require("react")),n=require("./is-empty-element"),r=require("./context");function o(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return o=function(){return e},e}function i(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=o();if(t&&t.has(e))return t.get(e);var n={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var u=r?Object.getOwnPropertyDescriptor(e,i):null;u&&(u.get||u.set)?Object.defineProperty(n,i,u):n[i]=e[i]}return n.default=e,t&&t.set(e,n),n}function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function c(e){return(c="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})(e)}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function f(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&f(e.prototype,t),n&&f(e,n),e}function s(e){return function(){var t,n=h(e);if(d()){var r=h(this).constructor;t=Reflect.construct(n,arguments,r)}else t=n.apply(this,arguments);return p(this,t)}}function p(e,t){return!t||"object"!==c(t)&&"function"!=typeof t?y(e):t}function y(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(){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(e){return!1}}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function b(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&m(e,t)}function m(e,t){return(m=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var v=function(r){b(i,t.Component);var o=s(i);function i(){var e;return l(this,i),(e=o.apply(this,arguments)).bindNode=e.bindNode.bind(y(e)),e}return a(i,[{key:"componentDidMount",value:function(){(0,this.props.registerSlot)(this.props.name,this)}},{key:"componentWillUnmount",value:function(){(0,this.props.unregisterSlot)(this.props.name,this)}},{key:"componentDidUpdate",value:function(e){var t=this.props,n=t.name,r=t.unregisterSlot,o=t.registerSlot;e.name!==n&&(r(e.name),o(n,this))}},{key:"bindNode",value:function(e){this.node=e}},{key:"render",value:function(){var r=this.props,o=r.children,i=r.name,u=r.fillProps,c=void 0===u?{}:u,l=r.getFills,f=(0,e.map)(l(i,this),function(n){var r=n.occurrence,o=(0,e.isFunction)(n.children)?n.children(c):n.children;return t.Children.map(o,function(n,o){if(!n||(0,e.isString)(n))return n;var i="".concat(r,"---").concat(n.key||o);return(0,t.cloneElement)(n,{key:i})})}).filter((0,e.negate)(n.isEmptyElement));return t.default.createElement(t.default.Fragment,null,(0,e.isFunction)(o)?o(f):f)}}]),i}(),g=function(e){return t.default.createElement(r.Consumer,null,function(n){var r=n.registerSlot,o=n.unregisterSlot,i=n.getFills;return t.default.createElement(v,u({},e,{registerSlot:r,unregisterSlot:o,getFills:i}))})},O=g;exports.default=O; | ||
},{"lodash":"u5no","react":"T5Ac","./is-empty-element":"Cej4","./context":"e4GB"}],"RmWj":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var e=require("lodash"),r=u(require("react")),t=require("./context");function n(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return n=function(){return e},e}function u(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var r=n();if(r&&r.has(e))return r.get(e);var t={},u=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var c in e)if(Object.prototype.hasOwnProperty.call(e,c)){var o=u?Object.getOwnPropertyDescriptor(e,c):null;o&&(o.get||o.set)?Object.defineProperty(t,c,o):t[c]=e[c]}return t.default=e,r&&r.set(e,t),t}function c(){return(c=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var o=0;function i(n){var u=n.name,c=n.children,i=n.registerFill,l=n.unregisterFill,a=(0,t.useSlot)(u),f=(0,r.useRef)({name:u,children:c});return f.current.occurrence||(f.current.occurrence=++o),(0,r.useLayoutEffect)(function(){return i(u,f.current),function(){return l(u,f.current)}},[]),(0,r.useLayoutEffect)(function(){f.current.children=c,a&&a.forceUpdate()},[c]),(0,r.useLayoutEffect)(function(){u!==f.current.name&&(l(f.current.name,f.current),f.current.name=u,i(u,f.current))},[u]),a&&a.node?((0,e.isFunction)(c)&&(c=c(a.props.fillProps)),(0,r.createPortal)(c,a.node)):null}var l=function(e){return r.default.createElement(t.Consumer,null,function(t){var n=t.registerFill,u=t.unregisterFill;return r.default.createElement(i,c({},e,{registerFill:n,unregisterFill:u}))})},a=l;exports.default=a; | ||
},{"lodash":"u5no","react":"T5Ac","./context":"e4GB"}],"XMs1":[function(require,module,exports) { | ||
"use strict";var r=Object.keys;function e(e,t){var n,u,i,o,f;if(e===t)return!0;if(n=r(e),u=r(t),n.length!==u.length)return!1;for(i=0;i<n.length;){if(void 0===(f=e[o=n[i]])&&!t.hasOwnProperty(o)||f!==t[o])return!1;i++}return!0}module.exports=e; | ||
},{}],"gYD6":[function(require,module,exports) { | ||
"use strict";function r(r,t){var e;if(r===t)return!0;if(r.length!==t.length)return!1;for(e=0;e<r.length;e++)if(r[e]!==t[e])return!1;return!0}module.exports=r; | ||
},{}],"yEpY":[function(require,module,exports) { | ||
"use strict";var r=require("./objects"),e=require("./arrays"),t=Array.isArray;function o(o,s){if(o&&s){if(o.constructor===Object&&s.constructor===Object)return r(o,s);if(t(o)&&t(s))return e(o,s)}return o===s}module.exports=o,module.exports.isShallowEqualObjects=r,module.exports.isShallowEqualArrays=e; | ||
},{"./objects":"XMs1","./arrays":"gYD6"}],"pXHF":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=i;var e=require("react"),t=r(require("./slot-fill-context"));function r(e){return e&&e.__esModule?e:{default:e}}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function l(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach(function(t){u(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function u(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(r){var n=(0,e.useContext)(t.default),u=n.slots[r]||{},i=n.fills[r],o=(0,e.useMemo)(function(){return i||[]},[i]);return l({},u,{updateSlot:(0,e.useCallback)(function(e,t){n.updateSlot(r,e,t)},[r,n.updateSlot]),unregisterSlot:(0,e.useCallback)(function(e){n.unregisterSlot(r,e)},[r,n.unregisterSlot]),fills:o,registerFill:(0,e.useCallback)(function(e){n.registerFill(r,e)},[r,n.registerFill]),unregisterFill:(0,e.useCallback)(function(e){n.unregisterFill(r,e)},[r,n.unregisterFill])})} | ||
},{"react":"T5Ac","./slot-fill-context":"W9Wi"}],"KSOQ":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=s;var e=l(require("react")),t=o(require("@wordpress/is-shallow-equal")),r=o(require("./slot-fill-context")),n=o(require("./use-slot"));function o(e){return e&&e.__esModule?e:{default:e}}function u(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return u=function(){return e},e}function l(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=u();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var l=n?Object.getOwnPropertyDescriptor(e,o):null;l&&(l.get||l.set)?Object.defineProperty(r,o,l):r[o]=e[o]}return r.default=e,t&&t.set(e,r),r}function f(){return(f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function i(e,t){if(null==e)return{};var r,n,o=a(e,t);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function a(e,t){if(null==e)return{};var r,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}function s(o){var u=o.name,l=o.fillProps,a=void 0===l?{}:l,s=o.as,c=void 0===s?"div":s,p=i(o,["name","fillProps","as"]),y=(0,e.useContext)(r.default),d=(0,e.useRef)(),O=(0,n.default)(u);return(0,e.useLayoutEffect)(function(){return y.registerSlot(u,d,a),function(){y.unregisterSlot(u,d)}},[y.registerSlot,y.unregisterSlot,u]),(0,e.useLayoutEffect)(function(){O.fillProps&&!(0,t.default)(O.fillProps,a)&&y.updateSlot(u,d,a)}),e.default.createElement(c,f({ref:d},p))} | ||
},{"react":"T5Ac","@wordpress/is-shallow-equal":"yEpY","./slot-fill-context":"W9Wi","./use-slot":"pXHF"}],"rkR6":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=u;var e=require("react"),r=t(require("./use-slot"));function t(e){return e&&e.__esModule?e:{default:e}}function u(t){var u=t.name,l=t.children,n=(0,r.default)(u),i=(0,e.useRef)();return(0,e.useEffect)(function(){return n.registerFill(i),function(){n.unregisterFill(i)}},[n.registerFill,n.unregisterFill]),n.ref&&n.ref.current?("function"==typeof l&&(l=l(n.fillProps)),(0,e.createPortal)(l,n.ref.current)):null} | ||
},{"react":"T5Ac","./use-slot":"pXHF"}],"Focm":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Slot=s,exports.Fill=b,exports.createSlotFill=d,Object.defineProperty(exports,"Provider",{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(exports,"useSlot",{enumerable:!0,get:function(){return a.default}});var e=o(require("react")),t=o(require("./slot")),r=o(require("./fill")),l=o(require("./context")),u=o(require("./bubbles-virtually/slot")),n=o(require("./bubbles-virtually/fill")),a=o(require("./bubbles-virtually/use-slot"));function o(e){return e&&e.__esModule?e:{default:e}}function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var l in r)Object.prototype.hasOwnProperty.call(r,l)&&(e[l]=r[l])}return e}).apply(this,arguments)}function f(e,t){if(null==e)return{};var r,l,u=c(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(l=0;l<n.length;l++)r=n[l],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(u[r]=e[r])}return u}function c(e,t){if(null==e)return{};var r,l,u={},n=Object.keys(e);for(l=0;l<n.length;l++)r=n[l],t.indexOf(r)>=0||(u[r]=e[r]);return u}function s(r){var l=r.bubblesVirtually,n=f(r,["bubblesVirtually"]);return l?e.default.createElement(u.default,n):e.default.createElement(t.default,n)}function b(t){return e.default.createElement(e.default.Fragment,null,e.default.createElement(r.default,t),e.default.createElement(n.default,t))}function d(t){var r=function(r){return e.default.createElement(b,i({name:t},r))};r.displayName=t+"Fill";var l=function(r){return e.default.createElement(s,i({name:t},r))};return l.displayName=t+"Slot",{Fill:r,Slot:l}} | ||
},{"react":"T5Ac","./slot":"LYME","./fill":"RmWj","./context":"e4GB","./bubbles-virtually/slot":"KSOQ","./bubbles-virtually/fill":"rkR6","./bubbles-virtually/use-slot":"pXHF"}]},{},["Focm"], null) | ||
//# sourceMappingURL=/index.js.map | ||
function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var e=require("react"),i=t(e),r=require("lodash"),s=t(require("@wordpress/is-shallow-equal"));function l(){return(l=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t}).apply(this,arguments)}function n(t,e){if(null==t)return{};var i,r,s={},l=Object.keys(t);for(r=0;r<l.length;r++)e.indexOf(i=l[r])>=0||(s[i]=t[i]);return s}function o(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var r=i.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}const u=t=>!r.isNumber(t)&&(r.isString(t)||r.isArray(t)?!t.length:!t),h=e.createContext({slots:{},fills:{},registerSlot:()=>{},unregisterSlot:()=>{},registerFill:()=>{},unregisterFill:()=>{}});function c({children:t}){const r=function(){const[t,i]=e.useState({}),[r,s]=e.useState({}),l=e.useCallback((t,e,r)=>{i(i=>Object.assign({},i,{[t]:Object.assign({},i[t],{ref:e||i[t].ref,fillProps:r||i[t].fillProps||{}})}))},[]),u=e.useCallback((t,e)=>{i(i=>{const{[t]:r}=i,s=n(i,[t].map(o));return r.ref===e?s:i})},[]),h=e.useCallback((t,e)=>{s(i=>Object.assign({},i,{[t]:[...i[t]||[],e]}))},[]),c=e.useCallback((t,e)=>{s(i=>i[t]?Object.assign({},i,{[t]:i[t].filter(t=>t!==e)}):i)},[]);return e.useMemo(()=>({slots:t,fills:r,registerSlot:l,updateSlot:l,unregisterSlot:u,registerFill:h,unregisterFill:c}),[t,r,l,u,h,c])}();return i.createElement(h.Provider,{value:r},t)}const g=e.createContext({registerSlot:()=>{},unregisterSlot:()=>{},registerFill:()=>{},unregisterFill:()=>{},getSlot:()=>{},getFills:()=>{},subscribe:()=>{}}),{Provider:f,Consumer:a}=g;class S extends e.Component{constructor(){super(...arguments),this.bindNode=this.bindNode.bind(this)}componentDidMount(){const{registerSlot:t}=this.props;t(this.props.name,this)}componentWillUnmount(){const{unregisterSlot:t}=this.props;t(this.props.name,this)}componentDidUpdate(t){const{name:e,unregisterSlot:i,registerSlot:r}=this.props;t.name!==e&&(i(t.name),r(e,this))}bindNode(t){this.node=t}render(){const{children:t,name:s,fillProps:l={},getFills:n}=this.props,o=r.map(n(s,this),t=>{const i=t.occurrence,s=r.isFunction(t.children)?t.children(l):t.children;return e.Children.map(s,(t,s)=>!t||r.isString(t)?t:e.cloneElement(t,{key:i+"---"+(t.key||s)}))}).filter(r.negate(u));return i.createElement(i.Fragment,null,r.isFunction(t)?t(o):o)}}const F=t=>i.createElement(a,null,({registerSlot:e,unregisterSlot:r,getFills:s})=>i.createElement(S,l({},t,{registerSlot:e,unregisterSlot:r,getFills:s})));let b=0;function p({name:t,children:i,registerFill:s,unregisterFill:l}){const n=(t=>{const{getSlot:i,subscribe:r}=e.useContext(g),[s,l]=e.useState(i(t));return e.useEffect(()=>(l(i(t)),r(()=>{l(i(t))})),[t]),s})(t),o=e.useRef({name:t,children:i});return o.current.occurrence||(o.current.occurrence=++b),e.useLayoutEffect(()=>(s(t,o.current),()=>l(t,o.current)),[]),e.useLayoutEffect(()=>{o.current.children=i,n&&n.forceUpdate()},[i]),e.useLayoutEffect(()=>{t!==o.current.name&&(l(o.current.name,o.current),o.current.name=t,s(t,o.current))},[t]),n&&n.node?(r.isFunction(i)&&(i=i(n.props.fillProps)),e.createPortal(i,n.node)):null}const d=t=>i.createElement(a,null,({registerFill:e,unregisterFill:r})=>i.createElement(p,l({},t,{registerFill:e,unregisterFill:r})));function m(t){const i=e.useContext(h),r=i.slots[t]||{},s=i.fills[t],l=e.useMemo(()=>s||[],[s]),n=e.useCallback((e,r)=>{i.updateSlot(t,e,r)},[t,i.updateSlot]),o=e.useCallback(e=>{i.unregisterSlot(t,e)},[t,i.unregisterSlot]),u=e.useCallback(e=>{i.registerFill(t,e)},[t,i.registerFill]),c=e.useCallback(e=>{i.unregisterFill(t,e)},[t,i.unregisterFill]);return Object.assign({},r,{updateSlot:n,unregisterSlot:o,fills:l,registerFill:u,unregisterFill:c})}function v(t){let{name:r,fillProps:o={},as:u="div"}=t,c=n(t,["name","fillProps","as"]);const g=e.useContext(h),f=e.useRef(),a=m(r);return e.useLayoutEffect(()=>(g.registerSlot(r,f,o),()=>{g.unregisterSlot(r,f)}),[g.registerSlot,g.unregisterSlot,r]),e.useLayoutEffect(()=>{a.fillProps&&!s(a.fillProps,o)&&g.updateSlot(r,f,o)}),i.createElement(u,l({ref:f},c))}function j({name:t,children:i}){const r=m(t),s=e.useRef();return e.useEffect(()=>(r.registerFill(s),()=>{r.unregisterFill(s)}),[r.registerFill,r.unregisterFill]),r.ref&&r.ref.current?("function"==typeof i&&(i=i(r.fillProps)),e.createPortal(i,r.ref.current)):null}function y(t){let{bubblesVirtually:e}=t,r=n(t,["bubblesVirtually"]);return i.createElement(e?v:F,r)}function O(t){return i.createElement(i.Fragment,null,i.createElement(d,t),i.createElement(j,t))}exports.Fill=O,exports.Provider=class extends e.Component{constructor(){super(...arguments),this.registerSlot=this.registerSlot.bind(this),this.registerFill=this.registerFill.bind(this),this.unregisterSlot=this.unregisterSlot.bind(this),this.unregisterFill=this.unregisterFill.bind(this),this.getSlot=this.getSlot.bind(this),this.getFills=this.getFills.bind(this),this.hasFills=this.hasFills.bind(this),this.subscribe=this.subscribe.bind(this),this.slots={},this.fills={},this.listeners=[],this.contextValue={registerSlot:this.registerSlot,unregisterSlot:this.unregisterSlot,registerFill:this.registerFill,unregisterFill:this.unregisterFill,getSlot:this.getSlot,getFills:this.getFills,hasFills:this.hasFills,subscribe:this.subscribe}}registerSlot(t,e){const i=this.slots[t];this.slots[t]=e,this.triggerListeners(),this.forceUpdateSlot(t),i&&i.forceUpdate()}registerFill(t,e){this.fills[t]=[...this.fills[t]||[],e],this.forceUpdateSlot(t)}unregisterSlot(t,e){this.slots[t]===e&&(delete this.slots[t],this.triggerListeners())}unregisterFill(t,e){this.fills[t]=r.without(this.fills[t],e),this.resetFillOccurrence(t),this.forceUpdateSlot(t)}getSlot(t){return this.slots[t]}getFills(t,e){return this.slots[t]!==e?[]:r.sortBy(this.fills[t],"occurrence")}hasFills(t){return this.fills[t]&&!!this.fills[t].length}resetFillOccurrence(t){r.forEach(this.fills[t],t=>{t.occurrence=void 0})}forceUpdateSlot(t){const e=this.getSlot(t);e&&e.forceUpdate()}triggerListeners(){this.listeners.forEach(t=>t())}subscribe(t){return this.listeners.push(t),()=>{this.listeners=r.without(this.listeners,t)}}render(){return i.createElement(f,{value:this.contextValue},i.createElement(c,null,this.props.children))}},exports.Slot=y,exports.createSlotFill=function(t){const e=e=>i.createElement(O,l({name:t},e));e.displayName=t+"Fill";const r=e=>i.createElement(y,l({name:t},e));return r.displayName=t+"Slot",{Fill:e,Slot:r}},exports.useSlot=m; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@humanmade/react-slot-fill", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"main": "dist/index.js", | ||
@@ -16,11 +16,10 @@ "repository": "https://github.com/humanmade/react-slot-fill", | ||
"devDependencies": { | ||
"klap": "^4.2.3", | ||
"lodash": "^4.17.15", | ||
"parcel-bundler": "^1.12.4", | ||
"parcel-plugin-externals": "^0.3.3-pre.20200323.2", | ||
"react": "^16.13" | ||
}, | ||
"scripts": { | ||
"build": "parcel build src/index.js", | ||
"build": "klap build", | ||
"prepublish": "npm run build" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
3
1
56100
957