@ctablex/core
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -5,2 +5,18 @@ # Changelog | ||
## [0.2.0](https://github.com/sahabpardaz/ctablex/compare/v0.1.0...v0.2.0) (2020-07-14) | ||
### ⚠ BREAKING CHANGES | ||
- rename context types and providers | ||
### Examples | ||
- **basic:** add basic example ([#11](https://github.com/sahabpardaz/ctablex/issues/11)) ([ecbf8cb](https://github.com/sahabpardaz/ctablex/commit/ecbf8cb2c52a5be5785e7c1dcca2547c8242df85)) | ||
### Documentations | ||
- **basic-example:** improve readme ([#18](https://github.com/sahabpardaz/ctablex/issues/18)) ([fa29cb8](https://github.com/sahabpardaz/ctablex/commit/fa29cb84c654f3d4b6fa81796d407f17d367ccf1)) | ||
* rename context types and providers ([#19](https://github.com/sahabpardaz/ctablex/issues/19)) ([a28ddc9](https://github.com/sahabpardaz/ctablex/commit/a28ddc9d1ab0c51d67bbf27c283d19f205f32fcf)) | ||
## [0.1.0](https://github.com/sahabpardaz/ctablex/compare/v0.0.1...v0.1.0) (2020-07-04) | ||
@@ -7,0 +23,0 @@ |
@@ -14,3 +14,3 @@ (function (global, factory) { | ||
if (context === undefined) { | ||
throw new Error('useColumnsContext must be used inside the <ColumnsContextProvider/>'); | ||
throw new Error('useColumns must be used inside the <ColumnsProvider/>'); | ||
} | ||
@@ -20,3 +20,3 @@ | ||
} | ||
function ColumnsContextProvider(props) { | ||
function ColumnsProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(ColumnsContext.Provider, { | ||
@@ -46,3 +46,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useTablePartContext must be used inside the <TablePartContextProvider/>'); | ||
throw new Error('useTablePart must be used inside the <TablePartProvider/>'); | ||
} | ||
@@ -52,3 +52,3 @@ | ||
} | ||
function TablePartContextProvider(props) { | ||
function TablePartProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(TablePartContext.Provider, { | ||
@@ -68,3 +68,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useDataContext must be used inside the <DataContextProvider/>'); | ||
throw new Error('useData must be used inside the <DataProvider/>'); | ||
} | ||
@@ -74,3 +74,3 @@ | ||
} | ||
function DataContextProvider(props) { | ||
function DataProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(DataContext.Provider, { | ||
@@ -85,7 +85,7 @@ value: props.value | ||
var data = useData(props.data); | ||
return /*#__PURE__*/React__default.createElement(DataContextProvider, { | ||
return /*#__PURE__*/React__default.createElement(DataProvider, { | ||
value: data | ||
}, /*#__PURE__*/React__default.createElement(TablePartContextProvider, { | ||
}, /*#__PURE__*/React__default.createElement(TablePartProvider, { | ||
value: "definition" | ||
}, /*#__PURE__*/React__default.createElement(ColumnsContextProvider, { | ||
}, /*#__PURE__*/React__default.createElement(ColumnsProvider, { | ||
value: columns | ||
@@ -95,51 +95,2 @@ }, children))); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
var defaultTableComponents = { | ||
@@ -154,12 +105,8 @@ Table: 'table', | ||
var TableComponentsContext = /*#__PURE__*/React.createContext(defaultTableComponents); | ||
function useTableComponentsContext() { | ||
function useTableComponents() { | ||
return React.useContext(TableComponentsContext); | ||
} | ||
function TableComponentsContextProvider(props) { | ||
var contextValue = useTableComponentsContext(); | ||
var value = React.useMemo(function () { | ||
return _objectSpread2(_objectSpread2({}, contextValue), props.value); | ||
}, [contextValue, props.value]); | ||
function TableComponentsProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(TableComponentsContext.Provider, { | ||
value: value | ||
value: props.value | ||
}, props.children); | ||
@@ -185,3 +132,3 @@ } | ||
if (context === undefined) { | ||
throw new Error('useRowDataContext must be used inside the <RowDataContextProvider/>'); | ||
throw new Error('useRowData must be used inside the <RowDataProvider/>'); | ||
} | ||
@@ -191,3 +138,3 @@ | ||
} | ||
function RowDataContextProvider(props) { | ||
function RowDataProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(RowDataContext.Provider, { | ||
@@ -230,3 +177,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useContentContext must be used inside the <ContentContextProvider/>'); | ||
throw new Error('useContent must be used inside the <ContentProvider/>'); | ||
} | ||
@@ -236,3 +183,3 @@ | ||
} | ||
function ContentContextProvider(props) { | ||
function ContentProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(ContentContext.Provider, { | ||
@@ -253,3 +200,3 @@ value: props.value | ||
var value = useContentValue(accessor); | ||
return /*#__PURE__*/React__default.createElement(ContentContextProvider, { | ||
return /*#__PURE__*/React__default.createElement(ContentProvider, { | ||
value: value | ||
@@ -262,3 +209,3 @@ }, children); | ||
children = props.children; | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React__default.createElement(ContentValue, { | ||
@@ -271,3 +218,3 @@ accessor: accessor | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React__default.createElement(Components.Th, null, children); | ||
@@ -299,4 +246,4 @@ } | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
return /*#__PURE__*/React__default.createElement(TablePartContextProvider, { | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React__default.createElement(TablePartProvider, { | ||
value: "header" | ||
@@ -307,3 +254,3 @@ }, /*#__PURE__*/React__default.createElement(Components.Thead, null, children)); | ||
function HeaderRow(props) { | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
var columns = useColumns(); | ||
@@ -318,3 +265,3 @@ return /*#__PURE__*/React__default.createElement(Components.Tr, null, columns); | ||
if (context === undefined) { | ||
throw new Error('useIndexContext must be used inside the <IndexContextProvider/>'); | ||
throw new Error('useIndex must be used inside the <IndexProvider/>'); | ||
} | ||
@@ -324,3 +271,3 @@ | ||
} | ||
function IndexContextProvider(props) { | ||
function IndexProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(IndexContext.Provider, { | ||
@@ -340,3 +287,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useCurrentValue must be used inside the <ItemContextProvider/>'); | ||
throw new Error('useCurrentValue must be used inside the <ItemProvider/>'); | ||
} | ||
@@ -346,3 +293,3 @@ | ||
} | ||
function CurrentValueContextProvider(props) { | ||
function CurrentValueProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(CurrentValueContext.Provider, { | ||
@@ -363,6 +310,6 @@ value: props.value | ||
return /*#__PURE__*/React__default.createElement(React.Fragment, null, values.map(function (value, index) { | ||
return /*#__PURE__*/React__default.createElement(CurrentValueContextProvider, { | ||
return /*#__PURE__*/React__default.createElement(CurrentValueProvider, { | ||
value: value, | ||
key: getKey(value, index) | ||
}, /*#__PURE__*/React__default.createElement(IndexContextProvider, { | ||
}, /*#__PURE__*/React__default.createElement(IndexProvider, { | ||
value: index | ||
@@ -391,6 +338,6 @@ }, children)); | ||
function Row(props) { | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
var columns = useColumns(); | ||
var row = useCurrentValue(props.row); | ||
return /*#__PURE__*/React__default.createElement(RowDataContextProvider, { | ||
return /*#__PURE__*/React__default.createElement(RowDataProvider, { | ||
value: row | ||
@@ -402,4 +349,4 @@ }, /*#__PURE__*/React__default.createElement(Components.Tr, null, columns)); | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
return /*#__PURE__*/React__default.createElement(TablePartContextProvider, { | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React__default.createElement(TablePartProvider, { | ||
value: "body" | ||
@@ -411,3 +358,3 @@ }, /*#__PURE__*/React__default.createElement(Components.Tbody, null, children)); | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React__default.createElement(Components.Table, null, children); | ||
@@ -421,10 +368,10 @@ } | ||
exports.ColumnsContext = ColumnsContext; | ||
exports.ColumnsContextProvider = ColumnsContextProvider; | ||
exports.ColumnsProvider = ColumnsProvider; | ||
exports.ContentContext = ContentContext; | ||
exports.ContentContextProvider = ContentContextProvider; | ||
exports.ContentProvider = ContentProvider; | ||
exports.ContentValue = ContentValue; | ||
exports.CurrentValueContext = CurrentValueContext; | ||
exports.CurrentValueContextProvider = CurrentValueContextProvider; | ||
exports.CurrentValueProvider = CurrentValueProvider; | ||
exports.DataContext = DataContext; | ||
exports.DataContextProvider = DataContextProvider; | ||
exports.DataProvider = DataProvider; | ||
exports.DataTable = DataTable; | ||
@@ -435,6 +382,6 @@ exports.DefaultContent = DefaultContent; | ||
exports.IndexContext = IndexContext; | ||
exports.IndexContextProvider = IndexContextProvider; | ||
exports.IndexProvider = IndexProvider; | ||
exports.Row = Row; | ||
exports.RowDataContext = RowDataContext; | ||
exports.RowDataContextProvider = RowDataContextProvider; | ||
exports.RowDataProvider = RowDataProvider; | ||
exports.Rows = Rows; | ||
@@ -444,6 +391,7 @@ exports.Table = Table; | ||
exports.TableComponentsContext = TableComponentsContext; | ||
exports.TableComponentsContextProvider = TableComponentsContextProvider; | ||
exports.TableComponentsProvider = TableComponentsProvider; | ||
exports.TableHeader = TableHeader; | ||
exports.TablePartContext = TablePartContext; | ||
exports.TablePartContextProvider = TablePartContextProvider; | ||
exports.TablePartProvider = TablePartProvider; | ||
exports.defaultTableComponents = defaultTableComponents; | ||
exports.findColumns = findColumns; | ||
@@ -459,3 +407,3 @@ exports.getValue = getValue; | ||
exports.useRowData = useRowData; | ||
exports.useTableComponentsContext = useTableComponentsContext; | ||
exports.useTableComponents = useTableComponents; | ||
exports.useTablePart = useTablePart; | ||
@@ -462,0 +410,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).ctablex={},e.React)}(this,(function(e,t){"use strict";var r="default"in t?t.default:t,n=t.createContext(void 0);function o(){var e=t.useContext(n);if(void 0===e)throw Error("useColumnsContext must be used inside the <ColumnsContextProvider/>");return e}function u(e){return r.createElement(n.Provider,{value:e.value},e.children)}function a(e){return!(!e||!e.__COLUMNS__)}function l(e){var t=null;return r.Children.forEach(e,(function(e){r.isValidElement(e)&&a(e.type)&&(t=e)})),t}var i=t.createContext(void 0);function c(){var e=t.useContext(i);if(void 0===e)throw Error("useTablePartContext must be used inside the <TablePartContextProvider/>");return e}function d(e){return r.createElement(i.Provider,{value:e.value},e.children)}var v=t.createContext(void 0);function s(e){var r=t.useContext(v);if(void 0!==e)return e;if(void 0===r)throw Error("useDataContext must be used inside the <DataContextProvider/>");return r}function f(e){return r.createElement(v.Provider,{value:e.value},e.children)}function C(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(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 x(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?m(Object(r),!0).forEach((function(t){C(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var h=t.createContext({Table:"table",Thead:"thead",Tbody:"tbody",Tr:"tr",Th:"th",Td:"td"});function b(){return t.useContext(h)}function E(e){var n=e.children;return"definition"===c()?null:r.createElement(t.Fragment,null,n)}E.__COLUMNS__=!0;var P=t.createContext(void 0);function p(){var e=t.useContext(P);if(void 0===e)throw Error("useRowDataContext must be used inside the <RowDataContextProvider/>");return e}function y(e){return r.createElement(P.Provider,{value:e.value},e.children)}function T(e,t){return null===t?null:"string"==typeof t?function(e,t){var r=t;return e.forEach((function(e){var t;r=null===(t=r)||void 0===t?void 0:t[e]})),r}(t.split("."),e):t(e)}function w(e){return T(p(),e)}var O=t.createContext(void 0);function D(){var e=t.useContext(O);if(void 0===e)throw Error("useContentContext must be used inside the <ContentContextProvider/>");return e}function g(e){return r.createElement(O.Provider,{value:e.value},e.children)}function j(e){var n=D();return r.createElement(t.Fragment,null,n)}function _(e){var t=e.accessor,n=e.children,o=void 0===n?r.createElement(j,null):n,u=w(t);return r.createElement(g,{value:u},o)}function R(e){var t=e.accessor,n=e.children,o=b();return r.createElement(_,{accessor:t},r.createElement(o.Td,null,n))}function V(e){var t=e.children,n=b();return r.createElement(n.Th,null,t)}var I=t.createContext(void 0);function M(e){return r.createElement(I.Provider,{value:e.value},e.children)}var S=t.createContext(void 0);function k(e){var r=t.useContext(S);if(void 0!==e)return e;if(void 0===r)throw Error("useCurrentValue must be used inside the <ItemContextProvider/>");return r}function F(e){return r.createElement(S.Provider,{value:e.value},e.children)}var H=function(e,t){return t};function A(e){var n=e.children,o=e.getKey,u=void 0===o?H:o;return r.createElement(t.Fragment,null,e.value.map((function(e,t){return r.createElement(F,{value:e,key:u(e,t)},r.createElement(M,{value:t},n))})))}e.ArrayOutput=A,e.Cell=R,e.Column=function(e){var t=e.children,n=void 0===t?r.createElement(j,null):t,o=e.accessor,u=void 0===o?null:o,a=e.header,l=c();return"header"===l?r.createElement(V,null,a):"body"===l?r.createElement(R,{accessor:u},n):null},e.Columns=E,e.ColumnsContext=n,e.ColumnsContextProvider=u,e.ContentContext=O,e.ContentContextProvider=g,e.ContentValue=_,e.CurrentValueContext=S,e.CurrentValueContextProvider=F,e.DataContext=v,e.DataContextProvider=f,e.DataTable=function(e){var t=e.children,n=l(t),o=s(e.data);return r.createElement(f,{value:o},r.createElement(d,{value:"definition"},r.createElement(u,{value:n},t)))},e.DefaultContent=j,e.HeaderCell=V,e.HeaderRow=function(e){var t=b(),n=o();return r.createElement(t.Tr,null,n)},e.IndexContext=I,e.IndexContextProvider=M,e.Row=function(e){var t=b(),n=o(),u=k(e.row);return r.createElement(y,{value:u},r.createElement(t.Tr,null,n))},e.RowDataContext=P,e.RowDataContextProvider=y,e.Rows=function(e){var n=e.children,o=e.keyAccessor,u=s(e.data),a=t.useMemo((function(){if(o)return function(e){return T(e,o)}}),[o]);return r.createElement(A,{value:u,getKey:a},n)},e.Table=function(e){var t=e.children,n=b();return r.createElement(n.Table,null,t)},e.TableBody=function(e){var t=e.children,n=b();return r.createElement(d,{value:"body"},r.createElement(n.Tbody,null,t))},e.TableComponentsContext=h,e.TableComponentsContextProvider=function(e){var n=b(),o=t.useMemo((function(){return x(x({},n),e.value)}),[n,e.value]);return r.createElement(h.Provider,{value:o},e.children)},e.TableHeader=function(e){var t=e.children,n=b();return r.createElement(d,{value:"header"},r.createElement(n.Thead,null,t))},e.TablePartContext=i,e.TablePartContextProvider=d,e.findColumns=l,e.getValue=T,e.isColumnsType=a,e.useColumns=o,e.useContent=D,e.useContentValue=w,e.useCurrentValue=k,e.useData=s,e.useIndex=function(){var e=t.useContext(I);if(void 0===e)throw Error("useIndexContext must be used inside the <IndexContextProvider/>");return e},e.useRowData=p,e.useTableComponentsContext=b,e.useTablePart=c,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).ctablex={},e.React)}(this,(function(e,t){"use strict";var r="default"in t?t.default:t,n=t.createContext(void 0);function u(){var e=t.useContext(n);if(void 0===e)throw Error("useColumns must be used inside the <ColumnsProvider/>");return e}function o(e){return r.createElement(n.Provider,{value:e.value},e.children)}function a(e){return!(!e||!e.__COLUMNS__)}function l(e){var t=null;return r.Children.forEach(e,(function(e){r.isValidElement(e)&&a(e.type)&&(t=e)})),t}var i=t.createContext(void 0);function c(){var e=t.useContext(i);if(void 0===e)throw Error("useTablePart must be used inside the <TablePartProvider/>");return e}function d(e){return r.createElement(i.Provider,{value:e.value},e.children)}var v=t.createContext(void 0);function s(e){var r=t.useContext(v);if(void 0!==e)return e;if(void 0===r)throw Error("useData must be used inside the <DataProvider/>");return r}function f(e){return r.createElement(v.Provider,{value:e.value},e.children)}var m={Table:"table",Thead:"thead",Tbody:"tbody",Tr:"tr",Th:"th",Td:"td"},C=t.createContext(m);function h(){return t.useContext(C)}function E(e){var n=e.children;return"definition"===c()?null:r.createElement(t.Fragment,null,n)}E.__COLUMNS__=!0;var x=t.createContext(void 0);function b(){var e=t.useContext(x);if(void 0===e)throw Error("useRowData must be used inside the <RowDataProvider/>");return e}function P(e){return r.createElement(x.Provider,{value:e.value},e.children)}function T(e,t){return null===t?null:"string"==typeof t?function(e,t){var r=t;return e.forEach((function(e){var t;r=null===(t=r)||void 0===t?void 0:t[e]})),r}(t.split("."),e):t(e)}function y(e){return T(b(),e)}var p=t.createContext(void 0);function w(){var e=t.useContext(p);if(void 0===e)throw Error("useContent must be used inside the <ContentProvider/>");return e}function D(e){return r.createElement(p.Provider,{value:e.value},e.children)}function _(e){var n=w();return r.createElement(t.Fragment,null,n)}function R(e){var t=e.accessor,n=e.children,u=void 0===n?r.createElement(_,null):n,o=y(t);return r.createElement(D,{value:o},u)}function V(e){var t=e.accessor,n=e.children,u=h();return r.createElement(R,{accessor:t},r.createElement(u.Td,null,n))}function g(e){var t=e.children,n=h();return r.createElement(n.Th,null,t)}var I=t.createContext(void 0);function M(e){return r.createElement(I.Provider,{value:e.value},e.children)}var O=t.createContext(void 0);function F(e){var r=t.useContext(O);if(void 0!==e)return e;if(void 0===r)throw Error("useCurrentValue must be used inside the <ItemProvider/>");return r}function H(e){return r.createElement(O.Provider,{value:e.value},e.children)}var j=function(e,t){return t};function k(e){var n=e.children,u=e.getKey,o=void 0===u?j:u;return r.createElement(t.Fragment,null,e.value.map((function(e,t){return r.createElement(H,{value:e,key:o(e,t)},r.createElement(M,{value:t},n))})))}e.ArrayOutput=k,e.Cell=V,e.Column=function(e){var t=e.children,n=void 0===t?r.createElement(_,null):t,u=e.accessor,o=void 0===u?null:u,a=e.header,l=c();return"header"===l?r.createElement(g,null,a):"body"===l?r.createElement(V,{accessor:o},n):null},e.Columns=E,e.ColumnsContext=n,e.ColumnsProvider=o,e.ContentContext=p,e.ContentProvider=D,e.ContentValue=R,e.CurrentValueContext=O,e.CurrentValueProvider=H,e.DataContext=v,e.DataProvider=f,e.DataTable=function(e){var t=e.children,n=l(t),u=s(e.data);return r.createElement(f,{value:u},r.createElement(d,{value:"definition"},r.createElement(o,{value:n},t)))},e.DefaultContent=_,e.HeaderCell=g,e.HeaderRow=function(e){var t=h(),n=u();return r.createElement(t.Tr,null,n)},e.IndexContext=I,e.IndexProvider=M,e.Row=function(e){var t=h(),n=u(),o=F(e.row);return r.createElement(P,{value:o},r.createElement(t.Tr,null,n))},e.RowDataContext=x,e.RowDataProvider=P,e.Rows=function(e){var n=e.children,u=e.keyAccessor,o=s(e.data),a=t.useMemo((function(){if(u)return function(e){return T(e,u)}}),[u]);return r.createElement(k,{value:o,getKey:a},n)},e.Table=function(e){var t=e.children,n=h();return r.createElement(n.Table,null,t)},e.TableBody=function(e){var t=e.children,n=h();return r.createElement(d,{value:"body"},r.createElement(n.Tbody,null,t))},e.TableComponentsContext=C,e.TableComponentsProvider=function(e){return r.createElement(C.Provider,{value:e.value},e.children)},e.TableHeader=function(e){var t=e.children,n=h();return r.createElement(d,{value:"header"},r.createElement(n.Thead,null,t))},e.TablePartContext=i,e.TablePartProvider=d,e.defaultTableComponents=m,e.findColumns=l,e.getValue=T,e.isColumnsType=a,e.useColumns=u,e.useContent=w,e.useContentValue=y,e.useCurrentValue=F,e.useData=s,e.useIndex=function(){var e=t.useContext(I);if(void 0===e)throw Error("useIndex must be used inside the <IndexProvider/>");return e},e.useRowData=b,e.useTableComponents=h,e.useTablePart=c,Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -1,2 +0,2 @@ | ||
import React, { createContext, useContext, useMemo, Fragment } from 'react'; | ||
import React, { createContext, useContext, Fragment, useMemo } from 'react'; | ||
@@ -8,3 +8,3 @@ var ColumnsContext = /*#__PURE__*/createContext(undefined); | ||
if (context === undefined) { | ||
throw new Error('useColumnsContext must be used inside the <ColumnsContextProvider/>'); | ||
throw new Error('useColumns must be used inside the <ColumnsProvider/>'); | ||
} | ||
@@ -14,3 +14,3 @@ | ||
} | ||
function ColumnsContextProvider(props) { | ||
function ColumnsProvider(props) { | ||
return /*#__PURE__*/React.createElement(ColumnsContext.Provider, { | ||
@@ -40,3 +40,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useTablePartContext must be used inside the <TablePartContextProvider/>'); | ||
throw new Error('useTablePart must be used inside the <TablePartProvider/>'); | ||
} | ||
@@ -46,3 +46,3 @@ | ||
} | ||
function TablePartContextProvider(props) { | ||
function TablePartProvider(props) { | ||
return /*#__PURE__*/React.createElement(TablePartContext.Provider, { | ||
@@ -62,3 +62,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useDataContext must be used inside the <DataContextProvider/>'); | ||
throw new Error('useData must be used inside the <DataProvider/>'); | ||
} | ||
@@ -68,3 +68,3 @@ | ||
} | ||
function DataContextProvider(props) { | ||
function DataProvider(props) { | ||
return /*#__PURE__*/React.createElement(DataContext.Provider, { | ||
@@ -79,7 +79,7 @@ value: props.value | ||
var data = useData(props.data); | ||
return /*#__PURE__*/React.createElement(DataContextProvider, { | ||
return /*#__PURE__*/React.createElement(DataProvider, { | ||
value: data | ||
}, /*#__PURE__*/React.createElement(TablePartContextProvider, { | ||
}, /*#__PURE__*/React.createElement(TablePartProvider, { | ||
value: "definition" | ||
}, /*#__PURE__*/React.createElement(ColumnsContextProvider, { | ||
}, /*#__PURE__*/React.createElement(ColumnsProvider, { | ||
value: columns | ||
@@ -89,51 +89,2 @@ }, children))); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
var defaultTableComponents = { | ||
@@ -148,12 +99,8 @@ Table: 'table', | ||
var TableComponentsContext = /*#__PURE__*/createContext(defaultTableComponents); | ||
function useTableComponentsContext() { | ||
function useTableComponents() { | ||
return useContext(TableComponentsContext); | ||
} | ||
function TableComponentsContextProvider(props) { | ||
var contextValue = useTableComponentsContext(); | ||
var value = useMemo(function () { | ||
return _objectSpread2(_objectSpread2({}, contextValue), props.value); | ||
}, [contextValue, props.value]); | ||
function TableComponentsProvider(props) { | ||
return /*#__PURE__*/React.createElement(TableComponentsContext.Provider, { | ||
value: value | ||
value: props.value | ||
}, props.children); | ||
@@ -179,3 +126,3 @@ } | ||
if (context === undefined) { | ||
throw new Error('useRowDataContext must be used inside the <RowDataContextProvider/>'); | ||
throw new Error('useRowData must be used inside the <RowDataProvider/>'); | ||
} | ||
@@ -185,3 +132,3 @@ | ||
} | ||
function RowDataContextProvider(props) { | ||
function RowDataProvider(props) { | ||
return /*#__PURE__*/React.createElement(RowDataContext.Provider, { | ||
@@ -224,3 +171,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useContentContext must be used inside the <ContentContextProvider/>'); | ||
throw new Error('useContent must be used inside the <ContentProvider/>'); | ||
} | ||
@@ -230,3 +177,3 @@ | ||
} | ||
function ContentContextProvider(props) { | ||
function ContentProvider(props) { | ||
return /*#__PURE__*/React.createElement(ContentContext.Provider, { | ||
@@ -247,3 +194,3 @@ value: props.value | ||
var value = useContentValue(accessor); | ||
return /*#__PURE__*/React.createElement(ContentContextProvider, { | ||
return /*#__PURE__*/React.createElement(ContentProvider, { | ||
value: value | ||
@@ -256,3 +203,3 @@ }, children); | ||
children = props.children; | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React.createElement(ContentValue, { | ||
@@ -265,3 +212,3 @@ accessor: accessor | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React.createElement(Components.Th, null, children); | ||
@@ -293,4 +240,4 @@ } | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
return /*#__PURE__*/React.createElement(TablePartContextProvider, { | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React.createElement(TablePartProvider, { | ||
value: "header" | ||
@@ -301,3 +248,3 @@ }, /*#__PURE__*/React.createElement(Components.Thead, null, children)); | ||
function HeaderRow(props) { | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
var columns = useColumns(); | ||
@@ -312,3 +259,3 @@ return /*#__PURE__*/React.createElement(Components.Tr, null, columns); | ||
if (context === undefined) { | ||
throw new Error('useIndexContext must be used inside the <IndexContextProvider/>'); | ||
throw new Error('useIndex must be used inside the <IndexProvider/>'); | ||
} | ||
@@ -318,3 +265,3 @@ | ||
} | ||
function IndexContextProvider(props) { | ||
function IndexProvider(props) { | ||
return /*#__PURE__*/React.createElement(IndexContext.Provider, { | ||
@@ -334,3 +281,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useCurrentValue must be used inside the <ItemContextProvider/>'); | ||
throw new Error('useCurrentValue must be used inside the <ItemProvider/>'); | ||
} | ||
@@ -340,3 +287,3 @@ | ||
} | ||
function CurrentValueContextProvider(props) { | ||
function CurrentValueProvider(props) { | ||
return /*#__PURE__*/React.createElement(CurrentValueContext.Provider, { | ||
@@ -357,6 +304,6 @@ value: props.value | ||
return /*#__PURE__*/React.createElement(Fragment, null, values.map(function (value, index) { | ||
return /*#__PURE__*/React.createElement(CurrentValueContextProvider, { | ||
return /*#__PURE__*/React.createElement(CurrentValueProvider, { | ||
value: value, | ||
key: getKey(value, index) | ||
}, /*#__PURE__*/React.createElement(IndexContextProvider, { | ||
}, /*#__PURE__*/React.createElement(IndexProvider, { | ||
value: index | ||
@@ -385,6 +332,6 @@ }, children)); | ||
function Row(props) { | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
var columns = useColumns(); | ||
var row = useCurrentValue(props.row); | ||
return /*#__PURE__*/React.createElement(RowDataContextProvider, { | ||
return /*#__PURE__*/React.createElement(RowDataProvider, { | ||
value: row | ||
@@ -396,4 +343,4 @@ }, /*#__PURE__*/React.createElement(Components.Tr, null, columns)); | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
return /*#__PURE__*/React.createElement(TablePartContextProvider, { | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React.createElement(TablePartProvider, { | ||
value: "body" | ||
@@ -405,6 +352,6 @@ }, /*#__PURE__*/React.createElement(Components.Tbody, null, children)); | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React.createElement(Components.Table, null, children); | ||
} | ||
export { ArrayOutput, Cell, Column, Columns, ColumnsContext, ColumnsContextProvider, ContentContext, ContentContextProvider, ContentValue, CurrentValueContext, CurrentValueContextProvider, DataContext, DataContextProvider, DataTable, DefaultContent, HeaderCell, HeaderRow, IndexContext, IndexContextProvider, Row, RowDataContext, RowDataContextProvider, Rows, Table, TableBody, TableComponentsContext, TableComponentsContextProvider, TableHeader, TablePartContext, TablePartContextProvider, findColumns, getValue, isColumnsType, useColumns, useContent, useContentValue, useCurrentValue, useData, useIndex, useRowData, useTableComponentsContext, useTablePart }; | ||
export { ArrayOutput, Cell, Column, Columns, ColumnsContext, ColumnsProvider, ContentContext, ContentProvider, ContentValue, CurrentValueContext, CurrentValueProvider, DataContext, DataProvider, DataTable, DefaultContent, HeaderCell, HeaderRow, IndexContext, IndexProvider, Row, RowDataContext, RowDataProvider, Rows, Table, TableBody, TableComponentsContext, TableComponentsProvider, TableHeader, TablePartContext, TablePartProvider, defaultTableComponents, findColumns, getValue, isColumnsType, useColumns, useContent, useContentValue, useCurrentValue, useData, useIndex, useRowData, useTableComponents, useTablePart }; |
190
index.d.ts
@@ -45,22 +45,22 @@ import { Context } from 'react'; | ||
export declare const ColumnsContext: Context<ColumnsContextType | undefined>; | ||
export declare const ColumnsContext: Context<ColumnsNode | undefined>; | ||
export declare function ColumnsContextProvider( | ||
props: ColumnsContextProviderProps, | ||
export declare type ColumnsNode = ReactNode; | ||
declare interface ColumnsOwnProps {} | ||
export declare type ColumnsProps = PropsWithChildren<ColumnsOwnProps>; | ||
export declare function ColumnsProvider( | ||
props: ColumnsProviderProps, | ||
): JSX.Element; | ||
declare interface ColumnsContextProviderOwnProps { | ||
value: ColumnsContextType; | ||
declare interface ColumnsProviderOwnProps { | ||
value: ColumnsNode; | ||
} | ||
export declare type ColumnsContextProviderProps = PropsWithChildren< | ||
ColumnsContextProviderOwnProps | ||
export declare type ColumnsProviderProps = PropsWithChildren< | ||
ColumnsProviderOwnProps | ||
>; | ||
export declare type ColumnsContextType = ReactNode; | ||
declare interface ColumnsOwnProps {} | ||
export declare type ColumnsProps = PropsWithChildren<ColumnsOwnProps>; | ||
export declare interface ColumnsType<D extends object = {}> { | ||
@@ -70,20 +70,18 @@ __COLUMNS__: true; | ||
export declare const ContentContext: Context< | ||
ContentContextType<any> | undefined | ||
>; | ||
export declare type Content<V> = V; | ||
export declare function ContentContextProvider<V>( | ||
props: ContentContextProviderProps<V>, | ||
export declare const ContentContext: Context<Content<any> | undefined>; | ||
export declare function ContentProvider<V>( | ||
props: ContentProviderProps<V>, | ||
): JSX.Element; | ||
declare interface ContentContextProviderOwnProps<V> { | ||
value: ContentContextType<V>; | ||
declare interface ContentProviderOwnProps<V> { | ||
value: Content<V>; | ||
} | ||
export declare type ContentContextProviderProps<V> = PropsWithChildren< | ||
ContentContextProviderOwnProps<V> | ||
export declare type ContentProviderProps<V> = PropsWithChildren< | ||
ContentProviderOwnProps<V> | ||
>; | ||
export declare type ContentContextType<V> = V; | ||
export declare function ContentValue<D, C>( | ||
@@ -101,32 +99,32 @@ props: ContentValueProps<D, C>, | ||
export declare type CurrentValue<V> = V; | ||
export declare const CurrentValueContext: Context< | ||
CurrentValueContextType<any> | undefined | ||
CurrentValue<any> | undefined | ||
>; | ||
export declare function CurrentValueContextProvider<V>( | ||
props: CurrentValueContextProviderProps<V>, | ||
export declare function CurrentValueProvider<V>( | ||
props: CurrentValueProviderProps<V>, | ||
): JSX.Element; | ||
export declare type CurrentValueContextProviderProps<V> = PropsWithChildren< | ||
ItemContextProviderOwnProps<V> | ||
export declare type CurrentValueProviderProps<V> = PropsWithChildren< | ||
ItemProviderOwnProps<V> | ||
>; | ||
export declare type CurrentValueContextType<V> = V; | ||
export declare type Data<D> = ReadonlyArray<D>; | ||
export declare const DataContext: Context<DataContextType<any> | undefined>; | ||
export declare const DataContext: Context<Data<any> | undefined>; | ||
export declare function DataContextProvider<D>( | ||
props: DataContextProviderProps<D>, | ||
export declare function DataProvider<D>( | ||
props: DataProviderProps<D>, | ||
): JSX.Element; | ||
declare interface DataContextProviderOwnProps<D> { | ||
value: DataContextType<D>; | ||
declare interface DataProviderOwnProps<D> { | ||
value: Data<D>; | ||
} | ||
export declare type DataContextProviderProps<D> = PropsWithChildren< | ||
DataContextProviderOwnProps<D> | ||
export declare type DataProviderProps<D> = PropsWithChildren< | ||
DataProviderOwnProps<D> | ||
>; | ||
export declare type DataContextType<D> = ReadonlyArray<D>; | ||
export declare function DataTable<D>(props: DataTableProps<D>): JSX.Element; | ||
@@ -150,2 +148,4 @@ | ||
export declare const defaultTableComponents: TableComponents; | ||
export declare function findColumns<D extends object = {}>( | ||
@@ -176,18 +176,16 @@ children: ReactNode, | ||
export declare const IndexContext: Context<IndexContextType | undefined>; | ||
export declare type Index = number; | ||
export declare function IndexContextProvider( | ||
props: IndexContextProviderProps, | ||
): JSX.Element; | ||
export declare const IndexContext: Context<Index | undefined>; | ||
declare interface IndexContextProviderOwnProps { | ||
value: IndexContextType; | ||
export declare function IndexProvider(props: IndexProviderProps): JSX.Element; | ||
declare interface IndexProviderOwnProps { | ||
value: Index; | ||
} | ||
export declare type IndexContextProviderProps = PropsWithChildren< | ||
IndexContextProviderOwnProps | ||
export declare type IndexProviderProps = PropsWithChildren< | ||
IndexProviderOwnProps | ||
>; | ||
export declare type IndexContextType = number; | ||
export declare function isColumnsType<D extends object = {}>( | ||
@@ -197,4 +195,4 @@ type: any, | ||
declare interface ItemContextProviderOwnProps<V> { | ||
value: CurrentValueContextType<V>; | ||
declare interface ItemProviderOwnProps<V> { | ||
value: CurrentValue<V>; | ||
} | ||
@@ -204,20 +202,18 @@ | ||
export declare const RowDataContext: Context< | ||
RowDataContextType<any> | undefined | ||
>; | ||
export declare type RowData<V> = V; | ||
export declare function RowDataContextProvider<V>( | ||
props: RowDataContextProviderProps<V>, | ||
export declare const RowDataContext: Context<RowData<any> | undefined>; | ||
export declare function RowDataProvider<V>( | ||
props: RowDataProviderProps<V>, | ||
): JSX.Element; | ||
declare interface RowDataContextProviderOwnProps<V> { | ||
value: RowDataContextType<V>; | ||
declare interface RowDataProviderOwnProps<V> { | ||
value: RowData<V>; | ||
} | ||
export declare type RowDataContextProviderProps<V> = PropsWithChildren< | ||
RowDataContextProviderOwnProps<V> | ||
export declare type RowDataProviderProps<V> = PropsWithChildren< | ||
RowDataProviderOwnProps<V> | ||
>; | ||
export declare type RowDataContextType<V> = V; | ||
declare interface RowOwnProps<D> { | ||
@@ -246,17 +242,3 @@ row?: D; | ||
export declare const TableComponentsContext: Context<TableComponentsContextType>; | ||
export declare function TableComponentsContextProvider( | ||
props: TableComponentsContextProviderProps, | ||
): JSX.Element; | ||
declare interface TableComponentsContextProviderOwnProps { | ||
value: Partial<TableComponentsContextType>; | ||
} | ||
export declare type TableComponentsContextProviderProps = PropsWithChildren< | ||
TableComponentsContextProviderOwnProps | ||
>; | ||
export declare interface TableComponentsContextType { | ||
export declare interface TableComponents { | ||
Table: ElementType; | ||
@@ -270,2 +252,16 @@ Thead: ElementType; | ||
export declare const TableComponentsContext: Context<TableComponents>; | ||
export declare function TableComponentsProvider( | ||
props: TableComponentsProviderProps, | ||
): JSX.Element; | ||
declare interface TableComponentsProviderOwnProps { | ||
value: TableComponents; | ||
} | ||
export declare type TableComponentsProviderProps = PropsWithChildren< | ||
TableComponentsProviderOwnProps | ||
>; | ||
export declare function TableHeader(props: TableHeaderProps): JSX.Element; | ||
@@ -279,20 +275,18 @@ | ||
export declare const TablePartContext: Context< | ||
TablePartContextType | undefined | ||
>; | ||
export declare type TablePart = TablePartType; | ||
export declare function TablePartContextProvider( | ||
props: TablePartContextProviderProps, | ||
export declare const TablePartContext: Context<TablePart | undefined>; | ||
export declare function TablePartProvider( | ||
props: TablePartProviderProps, | ||
): JSX.Element; | ||
declare interface TablePartContextProviderOwnProps { | ||
value: TablePartContextType; | ||
declare interface TablePartProviderOwnProps { | ||
value: TablePart; | ||
} | ||
export declare type TablePartContextProviderProps = PropsWithChildren< | ||
TablePartContextProviderOwnProps | ||
export declare type TablePartProviderProps = PropsWithChildren< | ||
TablePartProviderOwnProps | ||
>; | ||
export declare type TablePartContextType = TablePartType; | ||
export declare type TablePartType = 'definition' | 'header' | 'body' | string; | ||
@@ -302,5 +296,5 @@ | ||
export declare function useColumns(): ColumnsContextType; | ||
export declare function useColumns(): ColumnsNode; | ||
export declare function useContent<V>(): ContentContextType<V>; | ||
export declare function useContent<V>(): Content<V>; | ||
@@ -315,18 +309,14 @@ export declare function useContentValue<D, C>(accessor: null): null; | ||
export declare function useCurrentValue<V>( | ||
value?: V, | ||
): CurrentValueContextType<V>; | ||
export declare function useCurrentValue<V>(value?: V): CurrentValue<V>; | ||
export declare function useData<D>( | ||
value?: ReadonlyArray<D>, | ||
): DataContextType<D>; | ||
export declare function useData<D>(value?: ReadonlyArray<D>): Data<D>; | ||
export declare function useIndex(): IndexContextType; | ||
export declare function useIndex(): Index; | ||
export declare function useRowData<V>(): RowDataContextType<V>; | ||
export declare function useRowData<V>(): RowData<V>; | ||
export declare function useTableComponentsContext(): TableComponentsContextType; | ||
export declare function useTableComponents(): TableComponents; | ||
export declare function useTablePart(): TablePartContextType; | ||
export declare function useTablePart(): TablePart; | ||
export {}; |
@@ -15,3 +15,3 @@ 'use strict'; | ||
if (context === undefined) { | ||
throw new Error('useColumnsContext must be used inside the <ColumnsContextProvider/>'); | ||
throw new Error('useColumns must be used inside the <ColumnsProvider/>'); | ||
} | ||
@@ -21,3 +21,3 @@ | ||
} | ||
function ColumnsContextProvider(props) { | ||
function ColumnsProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(ColumnsContext.Provider, { | ||
@@ -47,3 +47,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useTablePartContext must be used inside the <TablePartContextProvider/>'); | ||
throw new Error('useTablePart must be used inside the <TablePartProvider/>'); | ||
} | ||
@@ -53,3 +53,3 @@ | ||
} | ||
function TablePartContextProvider(props) { | ||
function TablePartProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(TablePartContext.Provider, { | ||
@@ -69,3 +69,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useDataContext must be used inside the <DataContextProvider/>'); | ||
throw new Error('useData must be used inside the <DataProvider/>'); | ||
} | ||
@@ -75,3 +75,3 @@ | ||
} | ||
function DataContextProvider(props) { | ||
function DataProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(DataContext.Provider, { | ||
@@ -86,7 +86,7 @@ value: props.value | ||
var data = useData(props.data); | ||
return /*#__PURE__*/React__default.createElement(DataContextProvider, { | ||
return /*#__PURE__*/React__default.createElement(DataProvider, { | ||
value: data | ||
}, /*#__PURE__*/React__default.createElement(TablePartContextProvider, { | ||
}, /*#__PURE__*/React__default.createElement(TablePartProvider, { | ||
value: "definition" | ||
}, /*#__PURE__*/React__default.createElement(ColumnsContextProvider, { | ||
}, /*#__PURE__*/React__default.createElement(ColumnsProvider, { | ||
value: columns | ||
@@ -96,22 +96,2 @@ }, children))); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
var defineProperty = _defineProperty; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var defaultTableComponents = { | ||
@@ -126,12 +106,8 @@ Table: 'table', | ||
var TableComponentsContext = /*#__PURE__*/React.createContext(defaultTableComponents); | ||
function useTableComponentsContext() { | ||
function useTableComponents() { | ||
return React.useContext(TableComponentsContext); | ||
} | ||
function TableComponentsContextProvider(props) { | ||
var contextValue = useTableComponentsContext(); | ||
var value = React.useMemo(function () { | ||
return _objectSpread(_objectSpread({}, contextValue), props.value); | ||
}, [contextValue, props.value]); | ||
function TableComponentsProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(TableComponentsContext.Provider, { | ||
value: value | ||
value: props.value | ||
}, props.children); | ||
@@ -157,3 +133,3 @@ } | ||
if (context === undefined) { | ||
throw new Error('useRowDataContext must be used inside the <RowDataContextProvider/>'); | ||
throw new Error('useRowData must be used inside the <RowDataProvider/>'); | ||
} | ||
@@ -163,3 +139,3 @@ | ||
} | ||
function RowDataContextProvider(props) { | ||
function RowDataProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(RowDataContext.Provider, { | ||
@@ -202,3 +178,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useContentContext must be used inside the <ContentContextProvider/>'); | ||
throw new Error('useContent must be used inside the <ContentProvider/>'); | ||
} | ||
@@ -208,3 +184,3 @@ | ||
} | ||
function ContentContextProvider(props) { | ||
function ContentProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(ContentContext.Provider, { | ||
@@ -225,3 +201,3 @@ value: props.value | ||
var value = useContentValue(accessor); | ||
return /*#__PURE__*/React__default.createElement(ContentContextProvider, { | ||
return /*#__PURE__*/React__default.createElement(ContentProvider, { | ||
value: value | ||
@@ -234,3 +210,3 @@ }, children); | ||
children = props.children; | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React__default.createElement(ContentValue, { | ||
@@ -243,3 +219,3 @@ accessor: accessor | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React__default.createElement(Components.Th, null, children); | ||
@@ -271,4 +247,4 @@ } | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
return /*#__PURE__*/React__default.createElement(TablePartContextProvider, { | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React__default.createElement(TablePartProvider, { | ||
value: "header" | ||
@@ -279,3 +255,3 @@ }, /*#__PURE__*/React__default.createElement(Components.Thead, null, children)); | ||
function HeaderRow(props) { | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
var columns = useColumns(); | ||
@@ -290,3 +266,3 @@ return /*#__PURE__*/React__default.createElement(Components.Tr, null, columns); | ||
if (context === undefined) { | ||
throw new Error('useIndexContext must be used inside the <IndexContextProvider/>'); | ||
throw new Error('useIndex must be used inside the <IndexProvider/>'); | ||
} | ||
@@ -296,3 +272,3 @@ | ||
} | ||
function IndexContextProvider(props) { | ||
function IndexProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(IndexContext.Provider, { | ||
@@ -312,3 +288,3 @@ value: props.value | ||
if (context === undefined) { | ||
throw new Error('useCurrentValue must be used inside the <ItemContextProvider/>'); | ||
throw new Error('useCurrentValue must be used inside the <ItemProvider/>'); | ||
} | ||
@@ -318,3 +294,3 @@ | ||
} | ||
function CurrentValueContextProvider(props) { | ||
function CurrentValueProvider(props) { | ||
return /*#__PURE__*/React__default.createElement(CurrentValueContext.Provider, { | ||
@@ -335,6 +311,6 @@ value: props.value | ||
return /*#__PURE__*/React__default.createElement(React.Fragment, null, values.map(function (value, index) { | ||
return /*#__PURE__*/React__default.createElement(CurrentValueContextProvider, { | ||
return /*#__PURE__*/React__default.createElement(CurrentValueProvider, { | ||
value: value, | ||
key: getKey(value, index) | ||
}, /*#__PURE__*/React__default.createElement(IndexContextProvider, { | ||
}, /*#__PURE__*/React__default.createElement(IndexProvider, { | ||
value: index | ||
@@ -363,6 +339,6 @@ }, children)); | ||
function Row(props) { | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
var columns = useColumns(); | ||
var row = useCurrentValue(props.row); | ||
return /*#__PURE__*/React__default.createElement(RowDataContextProvider, { | ||
return /*#__PURE__*/React__default.createElement(RowDataProvider, { | ||
value: row | ||
@@ -374,4 +350,4 @@ }, /*#__PURE__*/React__default.createElement(Components.Tr, null, columns)); | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
return /*#__PURE__*/React__default.createElement(TablePartContextProvider, { | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React__default.createElement(TablePartProvider, { | ||
value: "body" | ||
@@ -383,3 +359,3 @@ }, /*#__PURE__*/React__default.createElement(Components.Tbody, null, children)); | ||
var children = props.children; | ||
var Components = useTableComponentsContext(); | ||
var Components = useTableComponents(); | ||
return /*#__PURE__*/React__default.createElement(Components.Table, null, children); | ||
@@ -393,10 +369,10 @@ } | ||
exports.ColumnsContext = ColumnsContext; | ||
exports.ColumnsContextProvider = ColumnsContextProvider; | ||
exports.ColumnsProvider = ColumnsProvider; | ||
exports.ContentContext = ContentContext; | ||
exports.ContentContextProvider = ContentContextProvider; | ||
exports.ContentProvider = ContentProvider; | ||
exports.ContentValue = ContentValue; | ||
exports.CurrentValueContext = CurrentValueContext; | ||
exports.CurrentValueContextProvider = CurrentValueContextProvider; | ||
exports.CurrentValueProvider = CurrentValueProvider; | ||
exports.DataContext = DataContext; | ||
exports.DataContextProvider = DataContextProvider; | ||
exports.DataProvider = DataProvider; | ||
exports.DataTable = DataTable; | ||
@@ -407,6 +383,6 @@ exports.DefaultContent = DefaultContent; | ||
exports.IndexContext = IndexContext; | ||
exports.IndexContextProvider = IndexContextProvider; | ||
exports.IndexProvider = IndexProvider; | ||
exports.Row = Row; | ||
exports.RowDataContext = RowDataContext; | ||
exports.RowDataContextProvider = RowDataContextProvider; | ||
exports.RowDataProvider = RowDataProvider; | ||
exports.Rows = Rows; | ||
@@ -416,6 +392,7 @@ exports.Table = Table; | ||
exports.TableComponentsContext = TableComponentsContext; | ||
exports.TableComponentsContextProvider = TableComponentsContextProvider; | ||
exports.TableComponentsProvider = TableComponentsProvider; | ||
exports.TableHeader = TableHeader; | ||
exports.TablePartContext = TablePartContext; | ||
exports.TablePartContextProvider = TablePartContextProvider; | ||
exports.TablePartProvider = TablePartProvider; | ||
exports.defaultTableComponents = defaultTableComponents; | ||
exports.findColumns = findColumns; | ||
@@ -431,3 +408,3 @@ exports.getValue = getValue; | ||
exports.useRowData = useRowData; | ||
exports.useTableComponentsContext = useTableComponentsContext; | ||
exports.useTableComponents = useTableComponents; | ||
exports.useTablePart = useTablePart; |
{ | ||
"name": "@ctablex/core", | ||
"description": "Flexible and powerful react table", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -37,3 +37,3 @@ "main": "lib/ctablex.js", | ||
"test": "libton-script test --coverage --verbose", | ||
"lint": "libton-script lint", | ||
"lint": "libton-script lint && eslint --max-warnings=0 examples/**/*.{ts,tsx}", | ||
"format": "libton-script format", | ||
@@ -40,0 +40,0 @@ "format:check": "libton-script format --check", |
@@ -25,3 +25,3 @@ # ctablex | ||
```js | ||
```tsx | ||
import React from 'react'; | ||
@@ -32,3 +32,2 @@ import { | ||
Column, | ||
IndexCell, | ||
Table, | ||
@@ -84,2 +83,4 @@ TableHeader, | ||
[live demo](https://codesandbox.io/s/github/sahabpardaz/ctablex/tree/master/examples/basic?file=/src/BasicTable.tsx), [source code](https://github.com/sahabpardaz/ctablex/tree/master/examples/basic) | ||
## Changelog | ||
@@ -86,0 +87,0 @@ |
export { DataTable } from './data/DataTable'; | ||
export { | ||
TableComponentsContext, | ||
useTableComponentsContext, | ||
TableComponentsContextProvider, | ||
useTableComponents, | ||
TableComponentsProvider, | ||
defaultTableComponents, | ||
} from './TableComponentsContext'; | ||
export { useData, DataContext, DataContextProvider } from './data/DataContext'; | ||
export { useData, DataContext, DataProvider } from './data/DataContext'; | ||
@@ -14,3 +15,3 @@ export { Columns } from './column/Columns'; | ||
ColumnsContext, | ||
ColumnsContextProvider, | ||
ColumnsProvider, | ||
} from './column/ColumnsContext'; | ||
@@ -28,3 +29,3 @@ export { isColumnsType } from './column/ColumnsType'; | ||
useRowData, | ||
RowDataContextProvider, | ||
RowDataProvider, | ||
RowDataContext, | ||
@@ -37,3 +38,3 @@ } from './row/RowDataContext'; | ||
TablePartContext, | ||
TablePartContextProvider, | ||
TablePartProvider, | ||
useTablePart, | ||
@@ -49,3 +50,3 @@ } from './table/TablePartContext'; | ||
ContentContext, | ||
ContentContextProvider, | ||
ContentProvider, | ||
useContent, | ||
@@ -57,11 +58,7 @@ } from './content/ContentContext'; | ||
useCurrentValue, | ||
CurrentValueContextProvider, | ||
CurrentValueProvider, | ||
CurrentValueContext, | ||
} from './array/CurrentValueContext'; | ||
export { | ||
useIndex, | ||
IndexContext, | ||
IndexContextProvider, | ||
} from './array/IndexContext'; | ||
export { useIndex, IndexContext, IndexProvider } from './array/IndexContext'; | ||
export { getValue } from './utils/getValue'; |
export { | ||
TableComponentsContextType, | ||
TableComponentsContextProviderProps, | ||
TableComponents, | ||
TableComponentsProviderProps, | ||
} from './TableComponentsContext'; | ||
export { | ||
CurrentValueContextType, | ||
CurrentValueContextProviderProps, | ||
CurrentValue, | ||
CurrentValueProviderProps, | ||
} from './array/CurrentValueContext'; | ||
export { | ||
IndexContextType, | ||
IndexContextProviderProps, | ||
} from './array/IndexContext'; | ||
export { | ||
ContentContextType, | ||
ContentContextProviderProps, | ||
} from './content/ContentContext'; | ||
export { | ||
ColumnsContextType, | ||
ColumnsContextProviderProps, | ||
} from './column/ColumnsContext'; | ||
export { Index, IndexProviderProps } from './array/IndexContext'; | ||
export { Content, ContentProviderProps } from './content/ContentContext'; | ||
export { ColumnsNode, ColumnsProviderProps } from './column/ColumnsContext'; | ||
export { ColumnsType } from './column/ColumnsType'; | ||
export { DataContextType, DataContextProviderProps } from './data/DataContext'; | ||
export { Data, DataProviderProps } from './data/DataContext'; | ||
export { RowData, RowDataProviderProps } from './row/RowDataContext'; | ||
export { | ||
RowDataContextType, | ||
RowDataContextProviderProps, | ||
} from './row/RowDataContext'; | ||
export { | ||
TablePartContextType, | ||
TablePart, | ||
TablePartType, | ||
TablePartContextProviderProps, | ||
TablePartProviderProps, | ||
} from './table/TablePartContext'; | ||
@@ -32,0 +20,0 @@ export { Accessor } from './utils/accessor'; |
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
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
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
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
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
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
90
0
95679
2153