Skip to content

Commit

Permalink
Merge branch 'master' into feat/add-required
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Jones authored and Ryan Jones committed Sep 10, 2019
2 parents 7af4de9 + 6b2e9dc commit 768dae2
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ let wait = time => new Promise(resolve => setTimeout(resolve, time))
--as target platform
react-dom (default)
react-native
react-pdf
--clean clean the autogenerated .view.js files
--local default local language, defaults to English (en)
--tools use with Views Tools, defauls to true when
Expand Down
2 changes: 1 addition & 1 deletion ensure-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function ensureFirstStoryIsOn(flow, key, stories) {
if (!stories.has(key)) return

let story = flow.get(key)
if (story.stories.size > 0) {
if (story && story.stories.size > 0) {
let index = 0
for (let id of story.stories) {
if (index === 0 || !story.isSeparate) {
Expand Down
1 change: 1 addition & 0 deletions fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import relativise from './relativise.js'
let morphFont = {
'react-dom': morphFontAsReactDom,
'react-native': morphFontAsReactNative,
'react-pdf': morphFontAsReactNative,
}

export async function ensureFontsDirectory(src) {
Expand Down
4 changes: 1 addition & 3 deletions morph/react-dom/get-value-for-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ export default (node, parent, state) => {
node.value === 'props.isValid')
) {
return {
[node.name]: `{${node.value.replace('props.', 'data.')} || ${
node.value
}}`,
[node.name]: `{${node.value.replace('props.', 'data.')}}`,
}
} else if (isValidImgSrc(node, parent)) {
return {
Expand Down
2 changes: 2 additions & 0 deletions morph/react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default ({
getSystemImport,
local,
localSupported,
reactNativeLibraryImport = 'react-native',
track,
view,
viewsById,
Expand Down Expand Up @@ -75,6 +76,7 @@ export default ({
testIdKey: 'testID',
testIds: {},
track,
reactNativeLibraryImport,
usedBlockNames: { [finalName]: 1, AutoSizer: 1, Column: 1, Table: 1 },
uses: [],
use(block, isLazy = false) {
Expand Down
4 changes: 1 addition & 3 deletions morph/react-native/get-value-for-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ export default (node, parent, state) => {
node.value === 'props.isInvalid')
) {
return {
[node.name]: `{${node.value.replace('props.', 'data.')} || ${
node.value
}}`,
[node.name]: `{${node.value.replace('props.', 'data.')}}`,
}
} else if (isValidImgSrc(node, parent)) {
return (
Expand Down
7 changes: 7 additions & 0 deletions morph/react-pdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import reactNativeMorph from './react-native.js'

export default options =>
reactNativeMorph({
...options,
reactNativeLibraryImport: '@react-pdf/renderer',
})
7 changes: 3 additions & 4 deletions morph/react/block-off-when.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ export function enter(node, parent, state) {
if (parent && !isList(parent)) state.render.push('{')
let value = onWhen.value
if (state.data && value === 'props.isInvalid') {
value = 'data.isInvalid || props.isInvalid'
}
if (state.data && value === 'props.isValid') {
value = 'data.isValid || props.isValid'
value = 'data.isInvalid'
} else if (state.data && value === 'props.isValid') {
value = 'data.isValid'
}
state.render.push(`${value} ? `)
} else if (isStory(node, state)) {
Expand Down
6 changes: 5 additions & 1 deletion morph/react/get-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ export default (state, getImport) => {
}

if (usesNative.length > 0) {
dependencies.push(`import { ${usesNative.join(', ')} } from 'react-native'`)
dependencies.push(
`import { ${usesNative.join(', ')} } from '${
state.reactNativeLibraryImport
}'`
)
}

if (state.track) {
Expand Down
4 changes: 3 additions & 1 deletion morph/react/property-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ let parseFormatValue = (value, type) => {

export function enter(node, parent, state) {
if (node.name === 'text' && parent.name === 'Text') {
if (hasCustomScopes(node, parent)) {
if (state.data && node.value === 'props.value') {
parent.explicitChildren = '{data.value}'
} else if (hasCustomScopes(node, parent)) {
parent.explicitChildren = wrap(getScopedCondition(node, parent))
} else if (isSlot(node)) {
parent.explicitChildren = wrap(node.value)
Expand Down
2 changes: 2 additions & 0 deletions morphers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import reactDom from './morph/react-dom.js'
import reactNative from './morph/react-native.js'
import reactPdf from './morph/react-pdf.js'

export default {
'react-dom': reactDom,
'react-native': reactNative,
'react-pdf': reactPdf,
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viewstools/morph",
"version": "19.7.2",
"version": "19.9.0",
"description": "Views language morpher",
"main": "index.js",
"type": "module",
Expand Down

0 comments on commit 768dae2

Please sign in to comment.