Revert "Improve Prop Typings for Modals. Remove instances of any
. (… (#813)
Revert "Improve Prop Typings for Modals. Remove instances of `any`. (#792)"
This reverts commit 629f326f4c
.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { create } from 'react-modal-promise'
|
||||
import { toolTips, useStore } from '../../useStore'
|
||||
import { BinaryPart, Identifier, Value } from '../../lang/wasm'
|
||||
import { Value } from '../../lang/wasm'
|
||||
import {
|
||||
getNodePathFromSourceRange,
|
||||
getNodeFromPath,
|
||||
@ -11,10 +12,7 @@ import {
|
||||
transformAstSketchLines,
|
||||
ConstraintType,
|
||||
} from '../../lang/std/sketchcombos'
|
||||
import {
|
||||
SetAngleLengthModal,
|
||||
createSetAngleLengthModal,
|
||||
} from '../SetAngleLengthModal'
|
||||
import { SetAngleLengthModal } from '../SetAngleLengthModal'
|
||||
import {
|
||||
createIdentifier,
|
||||
createVariableDeclaration,
|
||||
@ -22,7 +20,7 @@ import {
|
||||
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
||||
import { updateCursors } from '../../lang/util'
|
||||
|
||||
const getModalInfo = createSetAngleLengthModal(SetAngleLengthModal)
|
||||
const getModalInfo = create(SetAngleLengthModal as any)
|
||||
|
||||
type ButtonType = 'xAbs' | 'yAbs' | 'snapToYAxis' | 'snapToXAxis'
|
||||
|
||||
@ -100,67 +98,40 @@ export const SetAbsDistance = ({ buttonType }: { buttonType: ButtonType }) => {
|
||||
programMemory,
|
||||
referenceSegName: '',
|
||||
})
|
||||
|
||||
function transformValue(
|
||||
fv: Identifier | BinaryPart,
|
||||
transformInfos: TransformInfo[]
|
||||
) {
|
||||
return transformAstSketchLines({
|
||||
ast: JSON.parse(JSON.stringify(ast)),
|
||||
selectionRanges: selectionRanges,
|
||||
transformInfos,
|
||||
programMemory,
|
||||
referenceSegName: '',
|
||||
forceValueUsedInTransform: fv,
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
if (!isAlign) {
|
||||
const forceVal = valueUsedInTransform || 0
|
||||
|
||||
const { valueNode, variableName, newVariableInsertIndex, sign } =
|
||||
await getModalInfo({
|
||||
let forceVal = valueUsedInTransform || 0
|
||||
const { valueNode, variableName, newVariableInsertIndex, sign } =
|
||||
await (!isAlign &&
|
||||
getModalInfo({
|
||||
value: forceVal,
|
||||
valueName: disType === 'yAbs' ? 'yDis' : 'xDis',
|
||||
})
|
||||
} as any))
|
||||
let finalValue = isAlign
|
||||
? createIdentifier('_0')
|
||||
: removeDoubleNegatives(valueNode, sign, variableName)
|
||||
|
||||
const finalValue = removeDoubleNegatives(
|
||||
valueNode as BinaryPart,
|
||||
sign,
|
||||
variableName
|
||||
const { modifiedAst: _modifiedAst, pathToNodeMap } =
|
||||
transformAstSketchLines({
|
||||
ast: JSON.parse(JSON.stringify(ast)),
|
||||
selectionRanges: selectionRanges,
|
||||
transformInfos,
|
||||
programMemory,
|
||||
referenceSegName: '',
|
||||
forceValueUsedInTransform: finalValue,
|
||||
})
|
||||
if (variableName) {
|
||||
const newBody = [..._modifiedAst.body]
|
||||
newBody.splice(
|
||||
newVariableInsertIndex,
|
||||
0,
|
||||
createVariableDeclaration(variableName, valueNode)
|
||||
)
|
||||
const { modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap } =
|
||||
transformValue(finalValue, transformInfos)
|
||||
|
||||
if (variableName) {
|
||||
const newBody = [..._modifiedAst.body]
|
||||
newBody.splice(
|
||||
newVariableInsertIndex,
|
||||
0,
|
||||
createVariableDeclaration(variableName, valueNode)
|
||||
)
|
||||
_modifiedAst.body = newBody
|
||||
}
|
||||
|
||||
updateAst(_modifiedAst, true, {
|
||||
callBack: updateCursors(
|
||||
setCursor,
|
||||
selectionRanges,
|
||||
_pathToNodeMap
|
||||
),
|
||||
})
|
||||
} else {
|
||||
const { modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap } =
|
||||
transformValue(createIdentifier('_0'), transformInfos)
|
||||
updateAst(_modifiedAst, true, {
|
||||
callBack: updateCursors(
|
||||
setCursor,
|
||||
selectionRanges,
|
||||
_pathToNodeMap
|
||||
),
|
||||
})
|
||||
_modifiedAst.body = newBody
|
||||
}
|
||||
|
||||
updateAst(_modifiedAst, true, {
|
||||
callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
||||
})
|
||||
} catch (e) {
|
||||
console.log('error', e)
|
||||
}
|
||||
|
Reference in New Issue
Block a user