* Extend KCL argument input * Migrate length constraint to be a command * Add ability for `kcl` arguments to provide an initial variable name * Move named variable flow into command palette * Fix one e2e test * Remove unwanted `ZERO` behavior when length constraint has no `variableName` * Fix issue with `getSelectionCountByType` with sketches not yet in artifactGraph * Update broken constraint tests * Look at this (photo)Graph *in the voice of Nickelback* * Fix segment overlays tests, which had out-of-date selectors * Return early from `useConvertToVariable` if no selectionRanges * Fixup for review comment from #4677 (#4696) Signed-off-by: Nick Cameron <nrc@ncameron.org> * Invalidate nightly bucket files after publish (#4627) * Invalidate nightly bucket files after publish * Fix conflict resolution * Add some more warnings (#4697) * Add installation instructions for all platforms (#4592) * Add installation instructions for all platforms Fixes #4511 * Typo * Typo2 * Improve linux instructions, thanks @TomPridham Co-authored-by: Tom Pridham <pridham.tom@gmail.com> --------- Co-authored-by: Tom Pridham <pridham.tom@gmail.com> * Bump node to v22.12.0 (LTS) (#4706) * Point-and-click Shell (#4666) * WIP: experimenting with Loft UI Relates to #4470 * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Add selection guard * Working loft for two sketches in the right hardcoded order * First pass at handling more than 2 sketches * WIP selections * WIP selections * More checks * Appends the loft line after the 'last' sketch in the code * Clean up * Enable multiple selections after the button click * First point-click loft test (not working locally, loft gets inserted at the wrong place) * Lint * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * Clean up and working pw test * Add test for doesSceneHaveSweepableSketch with count = 2 * Clean up loftSketches function * Add pw test for preselected sketches * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger CI * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Move to fromPromise-based Actor * Move error logic out of loftSketches, fix pw tests * Remove comments * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger CI * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger CI * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Fix typo * Revert snapshots * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger CI * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * Trigger CI * WIP: initial shell code addition * Rollback pw values to pre cam change * WIP: more additions * WIP: closer * WIP: first time working shell mod * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * Add extrude lookup for more generic shell * Handle walls * Add pw tests for cap shell * Add shell wall test * Fix lint * Add selection guard and clean up * Lint fix * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * WIP mutliple faces * WIP circular dep * Lint * Look at this (photo)Graph *in the voice of Nickelback* * Trigger CI * Working multi-face shell across types * Cap and wall pw test * Apply suggestions from Frank's review Co-authored-by: Frank Noirot <frank@zoo.dev> * Fix test annotations * Add unit tests for doesSceneHaveExtrudedSketch * Manual resolution of snapshot conflicts * Fix assertParse * Updated pathToNode construct --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Frank Noirot <frank@zoo.dev> * More aggressive using of cache on engine settings changes (#4691) * move around the files for cache to better localtions Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * udpates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * cleanup Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * ensure we can change the grid setting via the command bar Signed-off-by: Jess Frazelle <github@jessfraz.com> * pass thru all setttings Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix playwright test Signed-off-by: Jess Frazelle <github@jessfraz.com> * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * emoty --------- Signed-off-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * fix use of `as` --------- Signed-off-by: Nick Cameron <nrc@ncameron.org> Signed-off-by: Jess Frazelle <github@jessfraz.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Nick Cameron <nrc@ncameron.org> Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com> Co-authored-by: Tom Pridham <pridham.tom@gmail.com> Co-authored-by: Jess Frazelle <jessfraz@users.noreply.github.com>
79 lines
2.3 KiB
TypeScript
79 lines
2.3 KiB
TypeScript
import {
|
|
SetVarNameModal,
|
|
createSetVarNameModal,
|
|
} from 'components/SetVarNameModal'
|
|
import { editorManager, kclManager, codeManager } from 'lib/singletons'
|
|
import { reportRejection, trap, err } from 'lib/trap'
|
|
import { moveValueIntoNewVariable } from 'lang/modifyAst'
|
|
import { isNodeSafeToReplace } from 'lang/queryAst'
|
|
import { useEffect, useState } from 'react'
|
|
import { useModelingContext } from './useModelingContext'
|
|
import { PathToNode, SourceRange, recast } from 'lang/wasm'
|
|
import { useKclContext } from 'lang/KclProvider'
|
|
import { toSync } from 'lib/utils'
|
|
|
|
export const getVarNameModal = createSetVarNameModal(SetVarNameModal)
|
|
|
|
export function useConvertToVariable(range?: SourceRange) {
|
|
const { ast } = useKclContext()
|
|
const { context } = useModelingContext()
|
|
const [enable, setEnabled] = useState(false)
|
|
|
|
useEffect(() => {
|
|
editorManager.convertToVariableEnabled = enable
|
|
}, [enable])
|
|
|
|
useEffect(() => {
|
|
// Return early if there are no selection ranges for whatever reason
|
|
if (!context.selectionRanges) return
|
|
const parsed = ast
|
|
|
|
const meta = isNodeSafeToReplace(
|
|
parsed,
|
|
range ||
|
|
context.selectionRanges.graphSelections?.[0]?.codeRef?.range ||
|
|
[]
|
|
)
|
|
if (trap(meta)) return
|
|
|
|
const { isSafe, value } = meta
|
|
const canReplace = isSafe && value.type !== 'Identifier'
|
|
const isOnlyOneSelection =
|
|
!!range || context.selectionRanges.graphSelections.length === 1
|
|
|
|
setEnabled(canReplace && isOnlyOneSelection)
|
|
}, [context.selectionRanges])
|
|
|
|
const handleClick = async (
|
|
valueName?: string
|
|
): Promise<PathToNode | undefined> => {
|
|
try {
|
|
const { variableName } = await getVarNameModal({
|
|
valueName: valueName || 'var',
|
|
})
|
|
|
|
const { modifiedAst: _modifiedAst, pathToReplacedNode } =
|
|
moveValueIntoNewVariable(
|
|
ast,
|
|
kclManager.programMemory,
|
|
range || context.selectionRanges.graphSelections[0]?.codeRef?.range,
|
|
variableName
|
|
)
|
|
|
|
await kclManager.updateAst(_modifiedAst, true)
|
|
|
|
const newCode = recast(_modifiedAst)
|
|
if (err(newCode)) return
|
|
codeManager.updateCodeEditor(newCode)
|
|
|
|
return pathToReplacedNode
|
|
} catch (e) {
|
|
console.log('error', e)
|
|
}
|
|
}
|
|
|
|
editorManager.convertToVariableCallback = toSync(handleClick, reportRejection)
|
|
|
|
return { enable, handleClick }
|
|
}
|