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,5 @@
|
|||||||
import { Dialog, Transition } from '@headlessui/react'
|
import { Dialog, Transition } from '@headlessui/react'
|
||||||
import { Fragment, useState } from 'react'
|
import { Fragment, useState } from 'react'
|
||||||
import { type InstanceProps, create } from 'react-modal-promise'
|
|
||||||
import { Value } from '../lang/wasm'
|
import { Value } from '../lang/wasm'
|
||||||
import {
|
import {
|
||||||
AvailableVars,
|
AvailableVars,
|
||||||
@ -10,28 +9,6 @@ import {
|
|||||||
CreateNewVariable,
|
CreateNewVariable,
|
||||||
} from './AvailableVarsHelpers'
|
} from './AvailableVarsHelpers'
|
||||||
|
|
||||||
type ModalResolve = {
|
|
||||||
value: string
|
|
||||||
sign: number
|
|
||||||
valueNode: Value
|
|
||||||
variableName?: string
|
|
||||||
newVariableInsertIndex: number
|
|
||||||
}
|
|
||||||
|
|
||||||
type ModalReject = boolean
|
|
||||||
|
|
||||||
type SetAngleLengthModalProps = InstanceProps<ModalResolve, ModalReject> & {
|
|
||||||
value: number
|
|
||||||
valueName: string
|
|
||||||
shouldCreateVariable?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export const createSetAngleLengthModal = create<
|
|
||||||
SetAngleLengthModalProps,
|
|
||||||
ModalResolve,
|
|
||||||
ModalReject
|
|
||||||
>
|
|
||||||
|
|
||||||
export const SetAngleLengthModal = ({
|
export const SetAngleLengthModal = ({
|
||||||
isOpen,
|
isOpen,
|
||||||
onResolve,
|
onResolve,
|
||||||
@ -39,7 +16,20 @@ export const SetAngleLengthModal = ({
|
|||||||
value: initialValue,
|
value: initialValue,
|
||||||
valueName,
|
valueName,
|
||||||
shouldCreateVariable: initialShouldCreateVariable = false,
|
shouldCreateVariable: initialShouldCreateVariable = false,
|
||||||
}: SetAngleLengthModalProps) => {
|
}: {
|
||||||
|
isOpen: boolean
|
||||||
|
onResolve: (a: {
|
||||||
|
value: string
|
||||||
|
sign: number
|
||||||
|
valueNode: Value
|
||||||
|
variableName?: string
|
||||||
|
newVariableInsertIndex: number
|
||||||
|
}) => void
|
||||||
|
onReject: (a: any) => void
|
||||||
|
value: number
|
||||||
|
valueName: string
|
||||||
|
shouldCreateVariable: boolean
|
||||||
|
}) => {
|
||||||
const [sign, setSign] = useState(Math.sign(Number(initialValue)))
|
const [sign, setSign] = useState(Math.sign(Number(initialValue)))
|
||||||
const [value, setValue] = useState(String(initialValue * sign))
|
const [value, setValue] = useState(String(initialValue * sign))
|
||||||
const [shouldCreateVariable, setShouldCreateVariable] = useState(
|
const [shouldCreateVariable, setShouldCreateVariable] = useState(
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { Dialog, Transition } from '@headlessui/react'
|
import { Dialog, Transition } from '@headlessui/react'
|
||||||
import { Fragment, useState } from 'react'
|
import { Fragment, useState } from 'react'
|
||||||
import { type InstanceProps, create } from 'react-modal-promise'
|
|
||||||
import { Value } from '../lang/wasm'
|
import { Value } from '../lang/wasm'
|
||||||
import {
|
import {
|
||||||
AvailableVars,
|
AvailableVars,
|
||||||
@ -10,30 +9,6 @@ import {
|
|||||||
CreateNewVariable,
|
CreateNewVariable,
|
||||||
} from './AvailableVarsHelpers'
|
} from './AvailableVarsHelpers'
|
||||||
|
|
||||||
type ModalResolve = {
|
|
||||||
value: string
|
|
||||||
segName: string
|
|
||||||
valueNode: Value
|
|
||||||
variableName?: string
|
|
||||||
newVariableInsertIndex: number
|
|
||||||
sign: number
|
|
||||||
}
|
|
||||||
|
|
||||||
type ModalReject = boolean
|
|
||||||
|
|
||||||
type GetInfoModalProps = InstanceProps<ModalResolve, ModalReject> & {
|
|
||||||
segName: string
|
|
||||||
isSegNameEditable: boolean
|
|
||||||
value?: number
|
|
||||||
initialVariableName: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export const createInfoModal = create<
|
|
||||||
GetInfoModalProps,
|
|
||||||
ModalResolve,
|
|
||||||
ModalReject
|
|
||||||
>
|
|
||||||
|
|
||||||
export const GetInfoModal = ({
|
export const GetInfoModal = ({
|
||||||
isOpen,
|
isOpen,
|
||||||
onResolve,
|
onResolve,
|
||||||
@ -42,12 +17,25 @@ export const GetInfoModal = ({
|
|||||||
isSegNameEditable,
|
isSegNameEditable,
|
||||||
value: initialValue,
|
value: initialValue,
|
||||||
initialVariableName,
|
initialVariableName,
|
||||||
}: GetInfoModalProps) => {
|
}: {
|
||||||
|
isOpen: boolean
|
||||||
|
onResolve: (a: {
|
||||||
|
value: string
|
||||||
|
segName: string
|
||||||
|
valueNode: Value
|
||||||
|
variableName?: string
|
||||||
|
newVariableInsertIndex: number
|
||||||
|
sign: number
|
||||||
|
}) => void
|
||||||
|
onReject: (a: any) => void
|
||||||
|
segName: string
|
||||||
|
isSegNameEditable: boolean
|
||||||
|
value: number
|
||||||
|
initialVariableName: string
|
||||||
|
}) => {
|
||||||
const [sign, setSign] = useState(Math.sign(Number(initialValue)))
|
const [sign, setSign] = useState(Math.sign(Number(initialValue)))
|
||||||
const [segName, setSegName] = useState(initialSegName)
|
const [segName, setSegName] = useState(initialSegName)
|
||||||
const [value, setValue] = useState(
|
const [value, setValue] = useState(String(Math.abs(initialValue)))
|
||||||
initialValue === undefined ? '' : String(Math.abs(initialValue))
|
|
||||||
)
|
|
||||||
const [shouldCreateVariable, setShouldCreateVariable] = useState(false)
|
const [shouldCreateVariable, setShouldCreateVariable] = useState(false)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -4,26 +4,19 @@ import { useCalc, CreateNewVariable } from './AvailableVarsHelpers'
|
|||||||
import { ActionButton } from './ActionButton'
|
import { ActionButton } from './ActionButton'
|
||||||
import { faPlus } from '@fortawesome/free-solid-svg-icons'
|
import { faPlus } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { toast } from 'react-hot-toast'
|
import { toast } from 'react-hot-toast'
|
||||||
import { type InstanceProps, create } from 'react-modal-promise'
|
|
||||||
|
|
||||||
type ModalResolve = { variableName: string }
|
|
||||||
type ModalReject = boolean
|
|
||||||
type SetVarNameModalProps = InstanceProps<ModalResolve, ModalReject> & {
|
|
||||||
valueName: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export const createSetVarNameModal = create<
|
|
||||||
SetVarNameModalProps,
|
|
||||||
ModalResolve,
|
|
||||||
ModalReject
|
|
||||||
>
|
|
||||||
|
|
||||||
export const SetVarNameModal = ({
|
export const SetVarNameModal = ({
|
||||||
isOpen,
|
isOpen,
|
||||||
onResolve,
|
onResolve,
|
||||||
onReject,
|
onReject,
|
||||||
valueName,
|
valueName,
|
||||||
}: SetVarNameModalProps) => {
|
}: {
|
||||||
|
isOpen: boolean
|
||||||
|
onResolve: (a: { variableName?: string }) => void
|
||||||
|
onReject: (a: any) => void
|
||||||
|
value: number
|
||||||
|
valueName: string
|
||||||
|
}) => {
|
||||||
const { isNewVariableNameUnique, newVariableName, setNewVariableName } =
|
const { isNewVariableNameUnique, newVariableName, setNewVariableName } =
|
||||||
useCalc({ value: '', initialVariableName: valueName })
|
useCalc({ value: '', initialVariableName: valueName })
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
|
import { create } from 'react-modal-promise'
|
||||||
import { toolTips, useStore } from '../../useStore'
|
import { toolTips, useStore } from '../../useStore'
|
||||||
import { BinaryPart, Value, VariableDeclarator } from '../../lang/wasm'
|
import { BinaryPart, Value, VariableDeclarator } from '../../lang/wasm'
|
||||||
import {
|
import {
|
||||||
@ -12,12 +13,12 @@ import {
|
|||||||
transformSecondarySketchLinesTagFirst,
|
transformSecondarySketchLinesTagFirst,
|
||||||
getTransformInfos,
|
getTransformInfos,
|
||||||
} from '../../lang/std/sketchcombos'
|
} from '../../lang/std/sketchcombos'
|
||||||
import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal'
|
import { GetInfoModal } from '../SetHorVertDistanceModal'
|
||||||
import { createVariableDeclaration } from '../../lang/modifyAst'
|
import { createVariableDeclaration } from '../../lang/modifyAst'
|
||||||
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
||||||
import { updateCursors } from '../../lang/util'
|
import { updateCursors } from '../../lang/util'
|
||||||
|
|
||||||
const getModalInfo = createInfoModal(GetInfoModal)
|
const getModalInfo = create(GetInfoModal as any)
|
||||||
|
|
||||||
export const Intersect = () => {
|
export const Intersect = () => {
|
||||||
const { guiMode, selectionRanges, ast, programMemory, updateAst, setCursor } =
|
const { guiMode, selectionRanges, ast, programMemory, updateAst, setCursor } =
|
||||||
@ -135,19 +136,20 @@ export const Intersect = () => {
|
|||||||
variableName,
|
variableName,
|
||||||
newVariableInsertIndex,
|
newVariableInsertIndex,
|
||||||
sign,
|
sign,
|
||||||
|
}: {
|
||||||
|
segName: string
|
||||||
|
value: number
|
||||||
|
valueNode: Value
|
||||||
|
variableName?: string
|
||||||
|
newVariableInsertIndex: number
|
||||||
|
sign: number
|
||||||
} = await getModalInfo({
|
} = await getModalInfo({
|
||||||
segName: tagInfo?.tag,
|
segName: tagInfo?.tag,
|
||||||
isSegNameEditable: !tagInfo?.isTagExisting,
|
isSegNameEditable: !tagInfo?.isTagExisting,
|
||||||
value: valueUsedInTransform,
|
value: valueUsedInTransform,
|
||||||
initialVariableName: 'offset',
|
initialVariableName: 'offset',
|
||||||
})
|
} as any)
|
||||||
if (
|
if (segName === tagInfo?.tag && value === valueUsedInTransform) {
|
||||||
segName === tagInfo?.tag &&
|
|
||||||
value ===
|
|
||||||
(valueUsedInTransform === undefined
|
|
||||||
? ''
|
|
||||||
: String(Math.abs(valueUsedInTransform)))
|
|
||||||
) {
|
|
||||||
updateAst(modifiedAst, true, {
|
updateAst(modifiedAst, true, {
|
||||||
callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
|
import { create } from 'react-modal-promise'
|
||||||
import { toolTips, useStore } from '../../useStore'
|
import { toolTips, useStore } from '../../useStore'
|
||||||
import { BinaryPart, Identifier, Value } from '../../lang/wasm'
|
import { Value } from '../../lang/wasm'
|
||||||
import {
|
import {
|
||||||
getNodePathFromSourceRange,
|
getNodePathFromSourceRange,
|
||||||
getNodeFromPath,
|
getNodeFromPath,
|
||||||
@ -11,10 +12,7 @@ import {
|
|||||||
transformAstSketchLines,
|
transformAstSketchLines,
|
||||||
ConstraintType,
|
ConstraintType,
|
||||||
} from '../../lang/std/sketchcombos'
|
} from '../../lang/std/sketchcombos'
|
||||||
import {
|
import { SetAngleLengthModal } from '../SetAngleLengthModal'
|
||||||
SetAngleLengthModal,
|
|
||||||
createSetAngleLengthModal,
|
|
||||||
} from '../SetAngleLengthModal'
|
|
||||||
import {
|
import {
|
||||||
createIdentifier,
|
createIdentifier,
|
||||||
createVariableDeclaration,
|
createVariableDeclaration,
|
||||||
@ -22,7 +20,7 @@ import {
|
|||||||
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
||||||
import { updateCursors } from '../../lang/util'
|
import { updateCursors } from '../../lang/util'
|
||||||
|
|
||||||
const getModalInfo = createSetAngleLengthModal(SetAngleLengthModal)
|
const getModalInfo = create(SetAngleLengthModal as any)
|
||||||
|
|
||||||
type ButtonType = 'xAbs' | 'yAbs' | 'snapToYAxis' | 'snapToXAxis'
|
type ButtonType = 'xAbs' | 'yAbs' | 'snapToYAxis' | 'snapToXAxis'
|
||||||
|
|
||||||
@ -100,39 +98,27 @@ export const SetAbsDistance = ({ buttonType }: { buttonType: ButtonType }) => {
|
|||||||
programMemory,
|
programMemory,
|
||||||
referenceSegName: '',
|
referenceSegName: '',
|
||||||
})
|
})
|
||||||
|
try {
|
||||||
|
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)
|
||||||
|
|
||||||
function transformValue(
|
const { modifiedAst: _modifiedAst, pathToNodeMap } =
|
||||||
fv: Identifier | BinaryPart,
|
transformAstSketchLines({
|
||||||
transformInfos: TransformInfo[]
|
|
||||||
) {
|
|
||||||
return transformAstSketchLines({
|
|
||||||
ast: JSON.parse(JSON.stringify(ast)),
|
ast: JSON.parse(JSON.stringify(ast)),
|
||||||
selectionRanges: selectionRanges,
|
selectionRanges: selectionRanges,
|
||||||
transformInfos,
|
transformInfos,
|
||||||
programMemory,
|
programMemory,
|
||||||
referenceSegName: '',
|
referenceSegName: '',
|
||||||
forceValueUsedInTransform: fv,
|
forceValueUsedInTransform: finalValue,
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!isAlign) {
|
|
||||||
const forceVal = valueUsedInTransform || 0
|
|
||||||
|
|
||||||
const { valueNode, variableName, newVariableInsertIndex, sign } =
|
|
||||||
await getModalInfo({
|
|
||||||
value: forceVal,
|
|
||||||
valueName: disType === 'yAbs' ? 'yDis' : 'xDis',
|
|
||||||
})
|
|
||||||
|
|
||||||
const finalValue = removeDoubleNegatives(
|
|
||||||
valueNode as BinaryPart,
|
|
||||||
sign,
|
|
||||||
variableName
|
|
||||||
)
|
|
||||||
const { modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap } =
|
|
||||||
transformValue(finalValue, transformInfos)
|
|
||||||
|
|
||||||
if (variableName) {
|
if (variableName) {
|
||||||
const newBody = [..._modifiedAst.body]
|
const newBody = [..._modifiedAst.body]
|
||||||
newBody.splice(
|
newBody.splice(
|
||||||
@ -144,23 +130,8 @@ export const SetAbsDistance = ({ buttonType }: { buttonType: ButtonType }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateAst(_modifiedAst, true, {
|
updateAst(_modifiedAst, true, {
|
||||||
callBack: updateCursors(
|
callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
||||||
setCursor,
|
|
||||||
selectionRanges,
|
|
||||||
_pathToNodeMap
|
|
||||||
),
|
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
const { modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap } =
|
|
||||||
transformValue(createIdentifier('_0'), transformInfos)
|
|
||||||
updateAst(_modifiedAst, true, {
|
|
||||||
callBack: updateCursors(
|
|
||||||
setCursor,
|
|
||||||
selectionRanges,
|
|
||||||
_pathToNodeMap
|
|
||||||
),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('error', e)
|
console.log('error', e)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
|
import { create } from 'react-modal-promise'
|
||||||
import { toolTips, useStore } from '../../useStore'
|
import { toolTips, useStore } from '../../useStore'
|
||||||
import { BinaryPart, Value, VariableDeclarator } from '../../lang/wasm'
|
import { BinaryPart, Value, VariableDeclarator } from '../../lang/wasm'
|
||||||
import {
|
import {
|
||||||
@ -11,12 +12,12 @@ import {
|
|||||||
transformSecondarySketchLinesTagFirst,
|
transformSecondarySketchLinesTagFirst,
|
||||||
getTransformInfos,
|
getTransformInfos,
|
||||||
} from '../../lang/std/sketchcombos'
|
} from '../../lang/std/sketchcombos'
|
||||||
import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal'
|
import { GetInfoModal } from '../SetHorVertDistanceModal'
|
||||||
import { createVariableDeclaration } from '../../lang/modifyAst'
|
import { createVariableDeclaration } from '../../lang/modifyAst'
|
||||||
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
||||||
import { updateCursors } from '../../lang/util'
|
import { updateCursors } from '../../lang/util'
|
||||||
|
|
||||||
const getModalInfo = createInfoModal(GetInfoModal)
|
const getModalInfo = create(GetInfoModal as any)
|
||||||
|
|
||||||
export const SetAngleBetween = () => {
|
export const SetAngleBetween = () => {
|
||||||
const { guiMode, selectionRanges, ast, programMemory, updateAst, setCursor } =
|
const { guiMode, selectionRanges, ast, programMemory, updateAst, setCursor } =
|
||||||
@ -94,19 +95,20 @@ export const SetAngleBetween = () => {
|
|||||||
variableName,
|
variableName,
|
||||||
newVariableInsertIndex,
|
newVariableInsertIndex,
|
||||||
sign,
|
sign,
|
||||||
|
}: {
|
||||||
|
segName: string
|
||||||
|
value: number
|
||||||
|
valueNode: Value
|
||||||
|
variableName?: string
|
||||||
|
newVariableInsertIndex: number
|
||||||
|
sign: number
|
||||||
} = await getModalInfo({
|
} = await getModalInfo({
|
||||||
segName: tagInfo?.tag,
|
segName: tagInfo?.tag,
|
||||||
isSegNameEditable: !tagInfo?.isTagExisting,
|
isSegNameEditable: !tagInfo?.isTagExisting,
|
||||||
value: valueUsedInTransform,
|
value: valueUsedInTransform,
|
||||||
initialVariableName: 'angle',
|
initialVariableName: 'angle',
|
||||||
})
|
} as any)
|
||||||
if (
|
if (segName === tagInfo?.tag && value === valueUsedInTransform) {
|
||||||
segName === tagInfo?.tag &&
|
|
||||||
value ===
|
|
||||||
(valueUsedInTransform === undefined
|
|
||||||
? ''
|
|
||||||
: String(Math.abs(valueUsedInTransform)))
|
|
||||||
) {
|
|
||||||
updateAst(modifiedAst, true, {
|
updateAst(modifiedAst, true, {
|
||||||
callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
|
import { create } from 'react-modal-promise'
|
||||||
import { toolTips, useStore } from '../../useStore'
|
import { toolTips, useStore } from '../../useStore'
|
||||||
import { BinaryPart, Value, VariableDeclarator } from '../../lang/wasm'
|
import { BinaryPart, Value, VariableDeclarator } from '../../lang/wasm'
|
||||||
import {
|
import {
|
||||||
@ -12,12 +13,12 @@ import {
|
|||||||
getTransformInfos,
|
getTransformInfos,
|
||||||
ConstraintType,
|
ConstraintType,
|
||||||
} from '../../lang/std/sketchcombos'
|
} from '../../lang/std/sketchcombos'
|
||||||
import { GetInfoModal, createInfoModal } from '../SetHorVertDistanceModal'
|
import { GetInfoModal } from '../SetHorVertDistanceModal'
|
||||||
import { createLiteral, createVariableDeclaration } from '../../lang/modifyAst'
|
import { createLiteral, createVariableDeclaration } from '../../lang/modifyAst'
|
||||||
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
||||||
import { updateCursors } from '../../lang/util'
|
import { updateCursors } from '../../lang/util'
|
||||||
|
|
||||||
const getModalInfo = createInfoModal(GetInfoModal)
|
const getModalInfo = create(GetInfoModal as any)
|
||||||
|
|
||||||
type ButtonType =
|
type ButtonType =
|
||||||
| 'setHorzDistance'
|
| 'setHorzDistance'
|
||||||
@ -118,8 +119,6 @@ export const SetHorzVertDistance = ({
|
|||||||
transformInfos,
|
transformInfos,
|
||||||
programMemory,
|
programMemory,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!isAlign) {
|
|
||||||
const {
|
const {
|
||||||
segName,
|
segName,
|
||||||
value,
|
value,
|
||||||
@ -127,37 +126,31 @@ export const SetHorzVertDistance = ({
|
|||||||
variableName,
|
variableName,
|
||||||
newVariableInsertIndex,
|
newVariableInsertIndex,
|
||||||
sign,
|
sign,
|
||||||
} = await getModalInfo({
|
}: {
|
||||||
|
segName: string
|
||||||
|
value: number
|
||||||
|
valueNode: Value
|
||||||
|
variableName?: string
|
||||||
|
newVariableInsertIndex: number
|
||||||
|
sign: number
|
||||||
|
} = await (!isAlign &&
|
||||||
|
getModalInfo({
|
||||||
segName: tagInfo?.tag,
|
segName: tagInfo?.tag,
|
||||||
isSegNameEditable: !tagInfo?.isTagExisting,
|
isSegNameEditable: !tagInfo?.isTagExisting,
|
||||||
value: valueUsedInTransform,
|
value: valueUsedInTransform,
|
||||||
initialVariableName:
|
initialVariableName:
|
||||||
constraint === 'setHorzDistance' ? 'xDis' : 'yDis',
|
constraint === 'setHorzDistance' ? 'xDis' : 'yDis',
|
||||||
})
|
} as any))
|
||||||
|
if (segName === tagInfo?.tag && value === valueUsedInTransform) {
|
||||||
if (
|
|
||||||
segName === tagInfo?.tag &&
|
|
||||||
value ===
|
|
||||||
(valueUsedInTransform === undefined
|
|
||||||
? ''
|
|
||||||
: String(Math.abs(valueUsedInTransform)))
|
|
||||||
) {
|
|
||||||
updateAst(modifiedAst, true, {
|
updateAst(modifiedAst, true, {
|
||||||
callBack: updateCursors(
|
callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
||||||
setCursor,
|
|
||||||
selectionRanges,
|
|
||||||
pathToNodeMap
|
|
||||||
),
|
|
||||||
})
|
})
|
||||||
}
|
} else {
|
||||||
|
let finalValue = isAlign
|
||||||
const finalValue = removeDoubleNegatives(
|
? createLiteral(0)
|
||||||
valueNode as BinaryPart,
|
: removeDoubleNegatives(valueNode as BinaryPart, sign, variableName)
|
||||||
sign,
|
// transform again but forcing certain values
|
||||||
variableName
|
const { modifiedAst: _modifiedAst, pathToNodeMap } =
|
||||||
)
|
|
||||||
|
|
||||||
const { modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap } =
|
|
||||||
transformSecondarySketchLinesTagFirst({
|
transformSecondarySketchLinesTagFirst({
|
||||||
ast,
|
ast,
|
||||||
selectionRanges,
|
selectionRanges,
|
||||||
@ -166,7 +159,6 @@ export const SetHorzVertDistance = ({
|
|||||||
forceSegName: segName,
|
forceSegName: segName,
|
||||||
forceValueUsedInTransform: finalValue,
|
forceValueUsedInTransform: finalValue,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (variableName) {
|
if (variableName) {
|
||||||
const newBody = [..._modifiedAst.body]
|
const newBody = [..._modifiedAst.body]
|
||||||
newBody.splice(
|
newBody.splice(
|
||||||
@ -176,24 +168,8 @@ export const SetHorzVertDistance = ({
|
|||||||
)
|
)
|
||||||
_modifiedAst.body = newBody
|
_modifiedAst.body = newBody
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAst(_modifiedAst, true, {
|
updateAst(_modifiedAst, true, {
|
||||||
callBack: updateCursors(setCursor, selectionRanges, _pathToNodeMap),
|
callBack: updateCursors(setCursor, selectionRanges, pathToNodeMap),
|
||||||
})
|
|
||||||
} else {
|
|
||||||
const finalValue = createLiteral(0)
|
|
||||||
|
|
||||||
const { modifiedAst: _modifiedAst, pathToNodeMap: _pathToNodeMap } =
|
|
||||||
transformSecondarySketchLinesTagFirst({
|
|
||||||
ast,
|
|
||||||
selectionRanges,
|
|
||||||
transformInfos,
|
|
||||||
programMemory,
|
|
||||||
forceValueUsedInTransform: finalValue,
|
|
||||||
})
|
|
||||||
|
|
||||||
updateAst(_modifiedAst, true, {
|
|
||||||
callBack: updateCursors(setCursor, selectionRanges, _pathToNodeMap),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
@ -21,7 +21,7 @@ import { removeDoubleNegatives } from '../AvailableVarsHelpers'
|
|||||||
import { normaliseAngle } from '../../lib/utils'
|
import { normaliseAngle } from '../../lib/utils'
|
||||||
import { updateCursors } from '../../lang/util'
|
import { updateCursors } from '../../lang/util'
|
||||||
|
|
||||||
const getModalInfo = create(SetAngleLengthModal)
|
const getModalInfo = create(SetAngleLengthModal as any)
|
||||||
|
|
||||||
type ButtonType = 'setAngle' | 'setLength'
|
type ButtonType = 'setAngle' | 'setLength'
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ export const SetAngleLength = ({
|
|||||||
value: forceVal,
|
value: forceVal,
|
||||||
valueName: angleOrLength === 'setAngle' ? 'angle' : 'length',
|
valueName: angleOrLength === 'setAngle' ? 'angle' : 'length',
|
||||||
shouldCreateVariable: true,
|
shouldCreateVariable: true,
|
||||||
})
|
} as any)
|
||||||
let finalValue = removeDoubleNegatives(valueNode, sign, variableName)
|
let finalValue = removeDoubleNegatives(valueNode, sign, variableName)
|
||||||
if (
|
if (
|
||||||
isReferencingYAxisAngle ||
|
isReferencingYAxisAngle ||
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import {
|
import { SetVarNameModal } from 'components/SetVarNameModal'
|
||||||
SetVarNameModal,
|
|
||||||
createSetVarNameModal,
|
|
||||||
} from 'components/SetVarNameModal'
|
|
||||||
import { moveValueIntoNewVariable } from 'lang/modifyAst'
|
import { moveValueIntoNewVariable } from 'lang/modifyAst'
|
||||||
import { isNodeSafeToReplace } from 'lang/queryAst'
|
import { isNodeSafeToReplace } from 'lang/queryAst'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
import { create } from 'react-modal-promise'
|
||||||
import { useStore } from 'useStore'
|
import { useStore } from 'useStore'
|
||||||
|
|
||||||
const getModalInfo = createSetVarNameModal(SetVarNameModal)
|
const getModalInfo = create(SetVarNameModal as any)
|
||||||
|
|
||||||
export function useConvertToVariable() {
|
export function useConvertToVariable() {
|
||||||
const { guiMode, selectionRanges, ast, programMemory, updateAst } = useStore(
|
const { guiMode, selectionRanges, ast, programMemory, updateAst } = useStore(
|
||||||
@ -39,7 +37,7 @@ export function useConvertToVariable() {
|
|||||||
try {
|
try {
|
||||||
const { variableName } = await getModalInfo({
|
const { variableName } = await getModalInfo({
|
||||||
valueName: 'var',
|
valueName: 'var',
|
||||||
})
|
} as any)
|
||||||
|
|
||||||
const { modifiedAst: _modifiedAst } = moveValueIntoNewVariable(
|
const { modifiedAst: _modifiedAst } = moveValueIntoNewVariable(
|
||||||
ast,
|
ast,
|
||||||
|
Reference in New Issue
Block a user