Skip to content

Commit

Permalink
Fixes #50
Browse files Browse the repository at this point in the history
Co-authored-by: MiquelCos <miquel@protofy.xyz>
  • Loading branch information
gdomenech98 and mikecmart committed Feb 8, 2024
1 parent bcb54fa commit 5e13543
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/protoflow/src/FlowBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Diff from 'deep-diff';
import DynamicCustomComponent from './DynamicCustomComponent';
import GetDynamicCustomComponent from './DynamicCustomComponent';
import { generateId } from './lib/IdGenerator';
import { getKindName } from './nodes/JsxElement';

interface customComponentInterface {
check: Function,
Expand Down Expand Up @@ -742,14 +743,15 @@ const FlowsBase = ({
const addedNodeData = Object.keys(initialNodeData).reduce((total, key) => {
var value: any = initialNodeData[key]
var keyName = `prop-${key}`

if (typeof value == "string" && key != "children") {
const valueType = typeof value
const valueKind = getKindName(value)
if (valueType == "string" && key != "children") {
value = '"' + value + '"'
} else if (typeof value == "object") {
} else if (valueType == "object" && !Array.isArray(value)) {
value = "{" + JSON.stringify(value) + "}"
}

var propValue = { key, value }
var propValue = { key, value, kind: valueKind }

if (key == 'children') {
keyName = 'child-1'
Expand Down
16 changes: 15 additions & 1 deletion packages/protoflow/src/nodes/JsxElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ JsxElement.dump = (node, nodes, edges, nodesData, metadata = null, enableMarkers

export default React.memo(JsxElement)

// TODO: export function to protolib
export function getKindName(value) {
switch (typeof value) {
case 'number':
return 'NumericLiteral'
case 'string':
return 'StringLiteral'
case 'boolean':
return 'TrueKeyword'
case 'object':
return Array.isArray(value) ? 'ArrayLiteralExpression' : 'ObjectLiteralExpression'
}
}
// TODO: export function to protolib
export function dumpAttributeData(attrData: {kind: string, value: any}): any {
const expressionKind = attrData.kind
var value = attrData.value
Expand All @@ -142,7 +156,7 @@ export function dumpAttributeData(attrData: {kind: string, value: any}): any {
}
return "{" + value + "}"
}

// TODO: export function to protolib
export function getAttributeData(node: any): any {
let atrVal
var attributeKind = node?.getKindName()
Expand Down

0 comments on commit 5e13543

Please sign in to comment.