Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
import { useSelector } from '@xstate/react'
|
|
|
|
import { useCommandsContext } from 'hooks/useCommandsContext'
|
2024-02-11 12:59:00 +11:00
|
|
|
import { useKclContext } from 'lang/KclSingleton'
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
import { CommandArgument } from 'lib/commandTypes'
|
|
|
|
import {
|
|
|
|
ResolvedSelectionType,
|
|
|
|
canSubmitSelectionArg,
|
|
|
|
getSelectionType,
|
|
|
|
getSelectionTypeDisplayText,
|
|
|
|
} from 'lib/selections'
|
|
|
|
import { modelingMachine } from 'machines/modelingMachine'
|
|
|
|
import { useEffect, useRef, useState } from 'react'
|
|
|
|
import { useHotkeys } from 'react-hotkeys-hook'
|
|
|
|
import { StateFrom } from 'xstate'
|
|
|
|
|
|
|
|
const selectionSelector = (snapshot: StateFrom<typeof modelingMachine>) =>
|
|
|
|
snapshot.context.selectionRanges
|
|
|
|
|
|
|
|
function CommandBarSelectionInput({
|
|
|
|
arg,
|
|
|
|
stepBack,
|
|
|
|
onSubmit,
|
|
|
|
}: {
|
|
|
|
arg: CommandArgument<unknown> & { inputType: 'selection'; name: string }
|
|
|
|
stepBack: () => void
|
|
|
|
onSubmit: (data: unknown) => void
|
|
|
|
}) {
|
|
|
|
const { code } = useKclContext()
|
|
|
|
const inputRef = useRef<HTMLInputElement>(null)
|
2024-02-08 12:59:01 -05:00
|
|
|
const { commandBarState, commandBarSend } = useCommandsContext()
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
const [hasSubmitted, setHasSubmitted] = useState(false)
|
|
|
|
const selection = useSelector(arg.actor, selectionSelector)
|
|
|
|
const [selectionsByType, setSelectionsByType] = useState<
|
|
|
|
'none' | ResolvedSelectionType[]
|
|
|
|
>(
|
|
|
|
selection.codeBasedSelections[0]?.range[1] === code.length
|
|
|
|
? 'none'
|
|
|
|
: getSelectionType(selection)
|
|
|
|
)
|
|
|
|
const [canSubmitSelection, setCanSubmitSelection] = useState<boolean>(
|
|
|
|
canSubmitSelectionArg(selectionsByType, arg)
|
|
|
|
)
|
|
|
|
|
|
|
|
useHotkeys('tab', () => onSubmit(selection), {
|
|
|
|
enableOnFormTags: true,
|
|
|
|
enableOnContentEditable: true,
|
|
|
|
keyup: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
inputRef.current?.focus()
|
|
|
|
}, [selection, inputRef])
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setSelectionsByType(
|
|
|
|
selection.codeBasedSelections[0]?.range[1] === code.length
|
|
|
|
? 'none'
|
|
|
|
: getSelectionType(selection)
|
|
|
|
)
|
|
|
|
}, [selection])
|
|
|
|
|
2024-02-08 12:59:01 -05:00
|
|
|
// Fast-forward through this arg if it's marked as skippable
|
|
|
|
// and we have a valid selection already
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
useEffect(() => {
|
|
|
|
setCanSubmitSelection(canSubmitSelectionArg(selectionsByType, arg))
|
2024-02-08 12:59:01 -05:00
|
|
|
const argValue = commandBarState.context.argumentsToSubmit[arg.name]
|
|
|
|
if (canSubmitSelection && arg.skip && argValue === undefined) {
|
|
|
|
handleSubmit({
|
|
|
|
preventDefault: () => {},
|
|
|
|
} as React.FormEvent<HTMLFormElement>)
|
|
|
|
}
|
Command bar: add extrude command, nonlinear editing, etc (#1204)
* Tweak toaster look and feel
* Add icons, tweak plus icon names
* Rename commandBarMeta to commandBarConfig
* Refactor command bar, add support for icons
* Create a tailwind plugin for aria-pressed button state
* Remove overlay from behind command bar
* Clean up toolbar
* Button and other style tweaks
* Icon tweaks follow-up: make old icons work with new sizing
* Delete unused static icons
* More CSS tweaks
* Small CSS tweak to project sidebar
* Add command bar E2E test
* fumpt
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* fix typo in a comment
* Fix icon padding (built version only)
* Update onboarding and warning banner icons padding
* Misc minor style fixes
* Get Extrude opening and canceling from command bar
* Iconography tweaks
* Get extrude kind of working
* Refactor command bar config types and organization
* Move command bar configs to be co-located with each other
* Start building a state machine for the command bar
* Start converting command bar to state machine
* Add support for multiple args, confirmation step
* Submission behavior, hotkeys, code organization
* Add new test for extruding from command bar
* Polish step back and selection hotkeys, CSS tweaks
* Loading style tweaks
* Validate selection inputs, polish UX of args re-editing
* Prevent submission with multiple selection on singlular arg
* Remove stray console logs
* Tweak test, CSS nit, remove extrude "result" argument
* Fix linting warnings
* Show Ctrl+/ instead of ⌘K on all platforms but Mac
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* Add "Enter sketch" to command bar
* fix command bar test
* Fix flaky cmd bar extrude test by waiting for engine select response
* Cover both button labels '⌘K' and 'Ctrl+/' in test
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-12-13 12:49:01 -05:00
|
|
|
}, [selectionsByType, arg])
|
|
|
|
|
|
|
|
function handleChange() {
|
|
|
|
inputRef.current?.focus()
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
if (!canSubmitSelection) {
|
|
|
|
setHasSubmitted(true)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit(selection)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<form id="arg-form" onSubmit={handleSubmit}>
|
|
|
|
<label
|
|
|
|
className={
|
|
|
|
'relative flex items-center mx-4 my-4 ' +
|
|
|
|
(!hasSubmitted || canSubmitSelection || 'text-destroy-50')
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{canSubmitSelection
|
|
|
|
? getSelectionTypeDisplayText(selection) + ' selected'
|
|
|
|
: `Please select ${arg.multiple ? 'one or more faces' : 'one face'}`}
|
|
|
|
<input
|
|
|
|
id="selection"
|
|
|
|
name="selection"
|
|
|
|
ref={inputRef}
|
|
|
|
required
|
|
|
|
placeholder="Select an entity with your mouse"
|
|
|
|
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
|
|
|
|
onKeyDown={(event) => {
|
|
|
|
if (event.key === 'Backspace') {
|
|
|
|
stepBack()
|
|
|
|
} else if (event.key === 'Escape') {
|
|
|
|
commandBarSend({ type: 'Close' })
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
onChange={handleChange}
|
|
|
|
value={JSON.stringify(selection || {})}
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
</form>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CommandBarSelectionInput
|