-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove ramda from layout package (#1827)
refactor: remove rambda from layout package
- Loading branch information
Showing
78 changed files
with
1,030 additions
and
872 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@react-pdf/layout': major | ||
'@react-pdf/examples': patch | ||
'@react-pdf/render': patch | ||
--- | ||
|
||
refactor: remove ramda from layout package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ges/layout/tests/utils/capitalize.test.js → packages/fns/capitalize.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const mapValues = (object, fn) => { | ||
const entries = Object.entries(object); | ||
|
||
return entries.reduce((acc, [key, value], index) => { | ||
acc[key] = fn(value, key, index); | ||
return acc; | ||
}, {}); | ||
}; | ||
|
||
export default mapValues; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...s/render/tests/utils/matchPercent.test.js → packages/fns/matchPercent.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const pick = (keys, obj) => { | ||
const result = {}; | ||
|
||
for (let i = 0; i < keys.length; i += 1) { | ||
const key = keys[i]; | ||
|
||
if (key in obj) result[key] = obj[key]; | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
export default pick; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Capitalize first letter of string | ||
* | ||
* @param {String} string | ||
* @returns {String} capitalized string | ||
*/ | ||
const upperFirst = value => { | ||
if (!value) return value; | ||
return value.charAt(0).toUpperCase() + value.slice(1); | ||
}; | ||
|
||
export default upperFirst; |
2 changes: 1 addition & 1 deletion
2
...ges/layout/tests/utils/upperFirst.test.js → packages/fns/upperFirst.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
import * as R from 'ramda'; | ||
import * as P from '@react-pdf/primitives'; | ||
|
||
const isType = R.propEq('type'); | ||
import isNil from '../../../fns/isNil'; | ||
|
||
const isSvg = isType(P.Svg); | ||
const NON_WRAP_TYPES = [P.Svg, P.Note, P.Image, P.Canvas]; | ||
|
||
const isNote = isType(P.Note); | ||
const getWrap = node => { | ||
if (NON_WRAP_TYPES.includes(node.type)) return false; | ||
|
||
const isImage = isType(P.Image); | ||
|
||
const isCanvas = isType(P.Canvas); | ||
|
||
const getWrap = R.ifElse( | ||
R.anyPass([isSvg, isNote, isImage, isCanvas]), | ||
R.always(false), | ||
R.pathOr(true, ['props', 'wrap']), | ||
); | ||
return isNil(node.props?.wrap) ? true : node.props.wrap; | ||
}; | ||
|
||
export default getWrap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import * as R from 'ramda'; | ||
|
||
const isFixed = R.pathEq(['props', 'fixed'], true); | ||
const isFixed = node => node.props?.fixed === true; | ||
|
||
export default isFixed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
import * as R from 'ramda'; | ||
|
||
import setPadding from './setPadding'; | ||
import omit from '../../../fns/omit'; | ||
|
||
const PADDING_PROPS = [ | ||
'padding', | ||
'paddingTop', | ||
'paddingRight', | ||
'paddingBottom', | ||
'paddingLeft', | ||
'paddingHorizontal', | ||
'paddingVertical', | ||
]; | ||
|
||
/** | ||
* Removes padding on node | ||
* | ||
* @param {Object} node | ||
* @returns {Object} node without padding | ||
*/ | ||
const removePaddings = R.compose( | ||
setPadding(0), | ||
R.dissocPath(['style', 'padding']), | ||
R.dissocPath(['style', 'paddingTop']), | ||
R.dissocPath(['style', 'paddingRight']), | ||
R.dissocPath(['style', 'paddingBottom']), | ||
R.dissocPath(['style', 'paddingLeft']), | ||
R.dissocPath(['style', 'paddingHorizontal']), | ||
R.dissocPath(['style', 'paddingVertical']), | ||
); | ||
const removePaddings = node => { | ||
const style = omit(PADDING_PROPS, node.style || {}); | ||
const newNode = Object.assign({}, node, { style }); | ||
|
||
setPadding(0)(newNode); | ||
|
||
return newNode; | ||
}; | ||
|
||
export default removePaddings; |
Oops, something went wrong.