@bemto/core
Advanced tools
Comparing version 0.1.0-alpha.1 to 0.1.0-alpha.2
@@ -100,3 +100,3 @@ 'use strict'; | ||
const bemto = (props, options) => { | ||
const bemto = (props, options = {}) => { | ||
const result = filterProps(props, options); | ||
@@ -113,23 +113,21 @@ | ||
const isRoot = !el || el === rootElem; | ||
let elementProps; | ||
let elementBlock; | ||
let elemProps; | ||
let elemBlock; | ||
if (isRoot) { | ||
elementBlock = result.blockNames.join(' '); | ||
elementProps = { ...result.rootProps }; | ||
elemBlock = result.blockNames.join(' '); | ||
elemProps = { ...options[el || rootElem], ...result.rootProps }; | ||
} else { | ||
elementBlock = getElement(result.blockNames, el).join(' '); | ||
elementProps = { ...result.elements[el] || {} }; | ||
elementProps.className = [ | ||
elementBlock, | ||
elementProps.className, | ||
].join(' ').trim(); | ||
elemBlock = getElement(result.blockNames, el).join(' '); | ||
elemProps = { ...options[el || rootElem], ...result.elements[el] }; | ||
elemProps.className = [elemBlock, elemProps.className].join(' ').trim(); | ||
} | ||
if (props) { | ||
elementProps.className = [ | ||
elementProps.className, | ||
bemto(props, { block: elementBlock }).rootProps.className | ||
].join(' ').trim(); | ||
const handledProps = bemto(props, { block: elemBlock }).rootProps; | ||
const className = elemProps.className; | ||
elemProps = { ...elemProps, ...handledProps }; | ||
elemProps.className = | ||
[className, handledProps.className].join(' ').trim(); | ||
} | ||
return elementProps; | ||
return elemProps; | ||
}; | ||
@@ -136,0 +134,0 @@ return result; |
@@ -96,3 +96,3 @@ const initialSettings = { | ||
const bemto = (props, options) => { | ||
const bemto = (props, options = {}) => { | ||
const result = filterProps(props, options); | ||
@@ -109,23 +109,21 @@ | ||
const isRoot = !el || el === rootElem; | ||
let elementProps; | ||
let elementBlock; | ||
let elemProps; | ||
let elemBlock; | ||
if (isRoot) { | ||
elementBlock = result.blockNames.join(' '); | ||
elementProps = { ...result.rootProps }; | ||
elemBlock = result.blockNames.join(' '); | ||
elemProps = { ...options[el || rootElem], ...result.rootProps }; | ||
} else { | ||
elementBlock = getElement(result.blockNames, el).join(' '); | ||
elementProps = { ...result.elements[el] || {} }; | ||
elementProps.className = [ | ||
elementBlock, | ||
elementProps.className, | ||
].join(' ').trim(); | ||
elemBlock = getElement(result.blockNames, el).join(' '); | ||
elemProps = { ...options[el || rootElem], ...result.elements[el] }; | ||
elemProps.className = [elemBlock, elemProps.className].join(' ').trim(); | ||
} | ||
if (props) { | ||
elementProps.className = [ | ||
elementProps.className, | ||
bemto(props, { block: elementBlock }).rootProps.className | ||
].join(' ').trim(); | ||
const handledProps = bemto(props, { block: elemBlock }).rootProps; | ||
const className = elemProps.className; | ||
elemProps = { ...elemProps, ...handledProps }; | ||
elemProps.className = | ||
[className, handledProps.className].join(' ').trim(); | ||
} | ||
return elementProps; | ||
return elemProps; | ||
}; | ||
@@ -132,0 +130,0 @@ return result; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).bemto={})}(this,function(e){"use strict";function s(e){return(s="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(n){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{},t=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(i).filter(function(e){return Object.getOwnPropertyDescriptor(i,e).enumerable}))),t.forEach(function(e){var t,o,r;t=n,r=i[o=e],o in t?Object.defineProperty(t,o,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[o]=r})}return n}var n={rootElem:"__Root",omitTrueModValue:!0,getters:{modifier:function(e){return 0===e.indexOf("_")?e.substring(1):e},element:function(e){return 0===e.indexOf("__")?e.substring(2):e}},templates:{modifier:function(e,t){return"".concat(e,"_").concat(t)},modifierValue:function(e,t){return"".concat(e,"_").concat(t)},element:function(e,t){return"".concat(e,"__").concat(t)}}},i=function(e){var c=e.omitTrueModValue,u=e.getters,f=e.templates,i=e.rootElem;return{getModifiers:function(e,s){return Object.keys(s).reduce(function(n,i){return s[i]&&e.map(function(e){return n.push((t=e,r=s[o=i],f.modifier(t,"boolean"==typeof r&&c?u.modifier(o):f.modifierValue(u.modifier(o),r))));var t,o,r}),n},[])},getElement:function(e,r){return e.map(function(e){return t=e,o=r,f.element(t,u.element(o));var t,o})},filterProps:function(n){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return Object.keys(n).reduce(function(e,t){var o,r;return 0===t.indexOf("__")?t!==i&&null!=(r=n[t])&&!1!==r&&(e.elements[t]="object"!==s(o=n[t])||o instanceof Array||o.props?{children:o}:o):0===t.indexOf("_")?e.modifiers[t]=n[t]:e.rootProps[t]=n[t],e},{rootProps:l({className:""},n[i]),blockNames:(e.block||n.className||"").split(/\s+/),elements:{},modifiers:{}})}}},t=function t(e){var s=e.rootElem,o=i(e),r=o.getModifiers,c=o.getElement,u=o.filterProps;return{withSettings:function(e){return t(l({},n,e,{getters:l({},n.getters,e.getters),templates:l({},n.templates,e.templates)}))},bemto:function n(e,t){var i=u(e,t);return i.rootProps.className=[i.rootProps.className,r(i.blockNames,i.modifiers).join(" ")].join(" ").trim(),i.elements[s]=i.rootProps,i.getProps=function(e,t){var o,r;return e&&e!==s?(r=c(i.blockNames,e).join(" "),(o=l({},i.elements[e]||{})).className=[r,o.className].join(" ").trim()):(r=i.blockNames.join(" "),o=l({},i.rootProps)),t&&(o.className=[o.className,n(t,{block:r}).rootProps.className].join(" ").trim()),o},i}}}(n),o=t.withSettings,r=t.bemto;e.withSettings=o,e.bemto=r,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).bemto={})}(this,function(e){"use strict";function s(e){return(s="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 a(n){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{},t=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(i).filter(function(e){return Object.getOwnPropertyDescriptor(i,e).enumerable}))),t.forEach(function(e){var t,o,r;t=n,r=i[o=e],o in t?Object.defineProperty(t,o,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[o]=r})}return n}var i={rootElem:"__Root",omitTrueModValue:!0,getters:{modifier:function(e){return 0===e.indexOf("_")?e.substring(1):e},element:function(e){return 0===e.indexOf("__")?e.substring(2):e}},templates:{modifier:function(e,t){return"".concat(e,"_").concat(t)},modifierValue:function(e,t){return"".concat(e,"_").concat(t)},element:function(e,t){return"".concat(e,"__").concat(t)}}},c=function(e){var c=e.omitTrueModValue,u=e.getters,f=e.templates,i=e.rootElem;return{getModifiers:function(e,s){return Object.keys(s).reduce(function(n,i){return s[i]&&e.map(function(e){return n.push((t=e,r=s[o=i],f.modifier(t,"boolean"==typeof r&&c?u.modifier(o):f.modifierValue(u.modifier(o),r))));var t,o,r}),n},[])},getElement:function(e,r){return e.map(function(e){return t=e,o=r,f.element(t,u.element(o));var t,o})},filterProps:function(n){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return Object.keys(n).reduce(function(e,t){var o,r;return 0===t.indexOf("__")?t!==i&&null!=(r=n[t])&&!1!==r&&(e.elements[t]="object"!==s(o=n[t])||o instanceof Array||o.props?{children:o}:o):0===t.indexOf("_")?e.modifiers[t]=n[t]:e.rootProps[t]=n[t],e},{rootProps:a({className:""},n[i]),blockNames:(e.block||n.className||"").split(/\s+/),elements:{},modifiers:{}})}}},t=function t(e){var f=e.rootElem,o=c(e),r=o.getModifiers,l=o.getElement,n=o.filterProps;return{withSettings:function(e){return t(a({},i,e,{getters:a({},i.getters,e.getters),templates:a({},i.templates,e.templates)}))},bemto:function s(e){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},u=n(e,c);return u.rootProps.className=[u.rootProps.className,r(u.blockNames,u.modifiers).join(" ")].join(" ").trim(),u.elements[f]=u.rootProps,u.getProps=function(e,t){var o,r;if(e&&e!==f?(r=l(u.blockNames,e).join(" "),(o=a({},c[e||f],u.elements[e])).className=[r,o.className].join(" ").trim()):(r=u.blockNames.join(" "),o=a({},c[e||f],u.rootProps)),t){var n=s(t,{block:r}).rootProps,i=o.className;(o=a({},o,n)).className=[i,n.className].join(" ").trim()}return o},u}}}(i),o=t.withSettings,r=t.bemto;e.withSettings=o,e.bemto=r,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "@bemto/core", | ||
"version": "0.1.0-alpha.1", | ||
"version": "0.1.0-alpha.2", | ||
"description": "", | ||
@@ -22,3 +22,3 @@ "author": "Roman Komarov <kizu@kizu.ru>", | ||
"test": "yarn build:testing && jest", | ||
"_prepare": "yarn lint && yarn build && yarn test" | ||
"prepare": "yarn lint && yarn build && yarn test" | ||
}, | ||
@@ -25,0 +25,0 @@ "repository": { |
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
14569
249