Comparing version 0.1.0 to 0.1.1-alpha.0
import React from 'react'; | ||
import { SubtreeProvider } from './Subtree'; | ||
import { RenderingArea } from './RenderingArea'; | ||
import { RenderToArea } from './RenderToArea'; | ||
export { SubtreeProvider, RenderingArea, RenderToArea }; | ||
import { AreaProvider } from './AreaContext'; | ||
import { RenderArea } from './RenderArea'; | ||
import { Content } from './Content'; | ||
export { AreaProvider, RenderArea, Content }; | ||
export declare function createRenderingPair(areaId: string): { | ||
RenderingArea: React.FC<{}>; | ||
RenderToArea: React.FC<{}>; | ||
RenderArea: React.FC<{}>; | ||
Content: React.FC<{}>; | ||
}; |
@@ -7,3 +7,4 @@ 'use strict'; | ||
var React = _interopDefault(require('react')); | ||
var React = require('react'); | ||
var React__default = _interopDefault(React); | ||
@@ -28,8 +29,5 @@ function _extends() { | ||
var useState = React.useState, | ||
useCallback = React.useCallback, | ||
useMemo = React.useMemo; | ||
var SubtreeContext = | ||
var AreaContext = | ||
/*#__PURE__*/ | ||
React.createContext({ | ||
React__default.createContext({ | ||
// @ts-ignore | ||
@@ -46,8 +44,8 @@ addComponent: function addComponent(areaId, component) {}, | ||
}); | ||
function SubtreeProvider(props) { | ||
var _useState = useState({}), | ||
function AreaProvider(props) { | ||
var _useState = React.useState({}), | ||
components = _useState[0], | ||
setComponents = _useState[1]; | ||
var addComponent = useCallback(function (areaId, component) { | ||
var addComponent = React.useCallback(function (areaId, component) { | ||
setComponents(function (components) { | ||
@@ -67,3 +65,3 @@ var _extends2; | ||
}, []); | ||
var removeComponent = useCallback(function (areaId, ref) { | ||
var removeComponent = React.useCallback(function (areaId, ref) { | ||
setComponents(function (components) { | ||
@@ -83,3 +81,3 @@ var existingComponents = components[areaId]; | ||
}, []); | ||
var updateComponent = useCallback(function (areaId, _component) { | ||
var updateComponent = React.useCallback(function (areaId, _component) { | ||
setComponents(function (components) { | ||
@@ -95,3 +93,3 @@ var existingComponents = components[areaId]; | ||
}, []); | ||
var getComponents = useCallback(function (areaId) { | ||
var getComponents = React.useCallback(function (areaId) { | ||
if (!(areaId in components)) { | ||
@@ -113,3 +111,3 @@ return null; | ||
}, [components]); | ||
var value = useMemo(function () { | ||
var value = React.useMemo(function () { | ||
return { | ||
@@ -122,3 +120,3 @@ addComponent: addComponent, | ||
}, [addComponent, getComponents, removeComponent, updateComponent]); | ||
return React.createElement(SubtreeContext.Provider, Object.assign({}, props, { | ||
return React__default.createElement(AreaContext.Provider, Object.assign({}, props, { | ||
value: value | ||
@@ -128,16 +126,18 @@ })); | ||
var useContext = React.useContext; | ||
var RenderingArea = function RenderingArea(_ref) { | ||
var areaId = _ref.areaId; | ||
var context = useContext(SubtreeContext); | ||
var children = context.getComponents(areaId); | ||
return children; | ||
var useContext = React__default.useContext; | ||
var EMPTY_ARRAY = []; | ||
var RenderArea = function RenderArea(_ref) { | ||
var areaId = _ref.areaId, | ||
children = _ref.children; | ||
var context = useContext(AreaContext); | ||
var components = context.getComponents(areaId); | ||
return typeof children === 'function' ? children(components || EMPTY_ARRAY) : components; | ||
}; | ||
var useEffect = React.useEffect, | ||
useContext$1 = React.useContext, | ||
useRef = React.useRef; | ||
var useEffect = React__default.useEffect, | ||
useContext$1 = React__default.useContext, | ||
useRef = React__default.useRef; | ||
var orderNumber = 0; | ||
function useRender(areaId, children) { | ||
var _useContext = useContext$1(SubtreeContext), | ||
var _useContext = useContext$1(AreaContext), | ||
addComponent = _useContext.addComponent, | ||
@@ -164,3 +164,3 @@ removeComponent = _useContext.removeComponent, | ||
} | ||
var RenderToArea = function RenderToArea(_ref) { | ||
var Content = function Content(_ref) { | ||
var areaId = _ref.areaId, | ||
@@ -175,4 +175,4 @@ children = _ref.children; | ||
pair.RenderingArea = function (props) { | ||
return React.createElement(RenderingArea, Object.assign({}, props, { | ||
pair.RenderArea = function (props) { | ||
return React__default.createElement(RenderArea, Object.assign({}, props, { | ||
areaId: areaId | ||
@@ -182,5 +182,5 @@ })); | ||
pair.RenderToArea = function (_ref) { | ||
pair.Content = function (_ref) { | ||
var children = _ref.children; | ||
return React.createElement(RenderToArea, { | ||
return React__default.createElement(Content, { | ||
areaId: areaId | ||
@@ -193,6 +193,6 @@ }, children); | ||
exports.RenderToArea = RenderToArea; | ||
exports.RenderingArea = RenderingArea; | ||
exports.SubtreeProvider = SubtreeProvider; | ||
exports.AreaProvider = AreaProvider; | ||
exports.Content = Content; | ||
exports.RenderArea = RenderArea; | ||
exports.createRenderingPair = createRenderingPair; | ||
//# sourceMappingURL=react-area.cjs.development.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=(e=require("react"))&&"object"==typeof e&&"default"in e?e.default:e;function r(){return(r=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 t=n.useState,o=n.useCallback,u=n.useMemo,a=n.createContext({addComponent:function(e,n){},removeComponent:function(e,n){},updateComponent:function(e,n){},getComponents:function(e){return null}}),c=n.useContext,i=function(e){var n=e.areaId;return c(a).getComponents(n)},f=n.useEffect,d=n.useContext,l=n.useRef,s=0,p=function(e){return n=e.areaId,r=e.children,t=d(a),o=t.addComponent,u=t.removeComponent,c=t.updateComponent,(i=l({value:r,orderNumber:null})).current.orderNumber=s,s+=1,f((function(){return o(n,i.current),function(){u(n,i.current)}}),[i.current,o,u]),f((function(){i.current.value=r,c(n,i.current)}),[r]),null;var n,r,t,o,u,c,i};exports.RenderToArea=p,exports.RenderingArea=i,exports.SubtreeProvider=function(e){var c=t({}),i=c[0],f=c[1],d=o((function(e,n){f((function(t){var o,u=t[e]||new Set;return u.has(n)?(console.log("component has already been registererd"),t):(u.add(n),r({},t,((o={})[e]=u,o)))}))}),[]),l=o((function(e,n){f((function(t){var o=t[e];return o?(o.delete(n),o.forEach((function(e){e.orderNumber=null})),r({},t)):t}))}),[]),s=o((function(e,n){f((function(n){return n[e]?r({},n):n}))}),[]),p=o((function(e){if(!(e in i))return null;var n=Array.from(i[e]);return n.sort((function(e,n){return e.orderNumber-n.orderNumber})),n.map((function(e){return e.value}))}),[i]),m=u((function(){return{addComponent:d,getComponents:p,removeComponent:l,updateComponent:s}}),[d,p,l,s]);return n.createElement(a.Provider,Object.assign({},e,{value:m}))},exports.createRenderingPair=function(e){return{RenderingArea:function(r){return n.createElement(i,Object.assign({},r,{areaId:e}))},RenderToArea:function(r){return n.createElement(p,{areaId:e},r.children)}}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("react"),r=(e=n)&&"object"==typeof e&&"default"in e?e.default:e;function t(){return(t=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 o=r.createContext({addComponent:function(e,n){},removeComponent:function(e,n){},updateComponent:function(e,n){},getComponents:function(e){return null}}),u=r.useContext,a=[],c=function(e){var n=e.areaId,r=e.children,t=u(o).getComponents(n);return"function"==typeof r?r(t||a):t},i=r.useEffect,f=r.useContext,l=r.useRef,d=0,s=function(e){return n=e.areaId,r=e.children,t=f(o),u=t.addComponent,a=t.removeComponent,c=t.updateComponent,(s=l({value:r,orderNumber:null})).current.orderNumber=d,d+=1,i((function(){return u(n,s.current),function(){a(n,s.current)}}),[s.current,u,a]),i((function(){s.current.value=r,c(n,s.current)}),[r]),null;var n,r,t,u,a,c,s};exports.AreaProvider=function(e){var u=n.useState({}),a=u[0],c=u[1],i=n.useCallback((function(e,n){c((function(r){var o,u=r[e]||new Set;return u.has(n)?(console.log("component has already been registererd"),r):(u.add(n),t({},r,((o={})[e]=u,o)))}))}),[]),f=n.useCallback((function(e,n){c((function(r){var o=r[e];return o?(o.delete(n),o.forEach((function(e){e.orderNumber=null})),t({},r)):r}))}),[]),l=n.useCallback((function(e,n){c((function(n){return n[e]?t({},n):n}))}),[]),d=n.useCallback((function(e){if(!(e in a))return null;var n=Array.from(a[e]);return n.sort((function(e,n){return e.orderNumber-n.orderNumber})),n.map((function(e){return e.value}))}),[a]),s=n.useMemo((function(){return{addComponent:i,getComponents:d,removeComponent:f,updateComponent:l}}),[i,d,f,l]);return r.createElement(o.Provider,Object.assign({},e,{value:s}))},exports.Content=s,exports.RenderArea=c,exports.createRenderingPair=function(e){return{RenderArea:function(n){return r.createElement(c,Object.assign({},n,{areaId:e}))},Content:function(n){return r.createElement(s,{areaId:e},n.children)}}}; | ||
//# sourceMappingURL=react-area.cjs.production.min.js.map |
@@ -1,2 +0,2 @@ | ||
import React from 'react'; | ||
import React, { useState, useCallback, useMemo } from 'react'; | ||
@@ -21,6 +21,3 @@ function _extends() { | ||
var useState = React.useState, | ||
useCallback = React.useCallback, | ||
useMemo = React.useMemo; | ||
var SubtreeContext = | ||
var AreaContext = | ||
/*#__PURE__*/ | ||
@@ -39,3 +36,3 @@ React.createContext({ | ||
}); | ||
function SubtreeProvider(props) { | ||
function AreaProvider(props) { | ||
var _useState = useState({}), | ||
@@ -111,3 +108,3 @@ components = _useState[0], | ||
}, [addComponent, getComponents, removeComponent, updateComponent]); | ||
return React.createElement(SubtreeContext.Provider, Object.assign({}, props, { | ||
return React.createElement(AreaContext.Provider, Object.assign({}, props, { | ||
value: value | ||
@@ -118,7 +115,9 @@ })); | ||
var useContext = React.useContext; | ||
var RenderingArea = function RenderingArea(_ref) { | ||
var areaId = _ref.areaId; | ||
var context = useContext(SubtreeContext); | ||
var children = context.getComponents(areaId); | ||
return children; | ||
var EMPTY_ARRAY = []; | ||
var RenderArea = function RenderArea(_ref) { | ||
var areaId = _ref.areaId, | ||
children = _ref.children; | ||
var context = useContext(AreaContext); | ||
var components = context.getComponents(areaId); | ||
return typeof children === 'function' ? children(components || EMPTY_ARRAY) : components; | ||
}; | ||
@@ -131,3 +130,3 @@ | ||
function useRender(areaId, children) { | ||
var _useContext = useContext$1(SubtreeContext), | ||
var _useContext = useContext$1(AreaContext), | ||
addComponent = _useContext.addComponent, | ||
@@ -154,3 +153,3 @@ removeComponent = _useContext.removeComponent, | ||
} | ||
var RenderToArea = function RenderToArea(_ref) { | ||
var Content = function Content(_ref) { | ||
var areaId = _ref.areaId, | ||
@@ -165,4 +164,4 @@ children = _ref.children; | ||
pair.RenderingArea = function (props) { | ||
return React.createElement(RenderingArea, Object.assign({}, props, { | ||
pair.RenderArea = function (props) { | ||
return React.createElement(RenderArea, Object.assign({}, props, { | ||
areaId: areaId | ||
@@ -172,5 +171,5 @@ })); | ||
pair.RenderToArea = function (_ref) { | ||
pair.Content = function (_ref) { | ||
var children = _ref.children; | ||
return React.createElement(RenderToArea, { | ||
return React.createElement(Content, { | ||
areaId: areaId | ||
@@ -183,3 +182,3 @@ }, children); | ||
export { RenderToArea, RenderingArea, SubtreeProvider, createRenderingPair }; | ||
export { AreaProvider, Content, RenderArea, createRenderingPair }; | ||
//# sourceMappingURL=react-area.esm.js.map |
{ | ||
"version": "0.1.0", | ||
"version": "0.1.1-alpha.0", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
43182
353