2023-12-06 14:44:13 -05:00
|
|
|
import { WheelEvent, useRef, useMemo } from 'react'
|
2023-10-11 15:12:29 +11:00
|
|
|
import { isCursorInSketchCommandRange } from 'lang/util'
|
2023-09-25 19:49:53 -07:00
|
|
|
import { engineCommandManager } from './lang/std/engineConnection'
|
2023-10-11 13:36:54 +11:00
|
|
|
import { useModelingContext } from 'hooks/useModelingContext'
|
2023-12-06 14:44:13 -05:00
|
|
|
import { useCommandsContext } from 'hooks/useCommandsContext'
|
|
|
|
import { ActionButton } from 'components/ActionButton'
|
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 usePlatform from 'hooks/usePlatform'
|
2024-02-19 17:23:03 +11:00
|
|
|
import { isSingleCursorInPipe } from 'lang/queryAst'
|
|
|
|
import { kclManager } from 'lang/KclSingleton'
|
2023-09-16 01:23:11 -04:00
|
|
|
|
2022-11-27 14:06:33 +11:00
|
|
|
export const Toolbar = () => {
|
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 platform = usePlatform()
|
|
|
|
const { commandBarSend } = useCommandsContext()
|
2023-10-11 13:36:54 +11:00
|
|
|
const { state, send, context } = useModelingContext()
|
2023-12-06 14:44:13 -05:00
|
|
|
const toolbarButtonsRef = useRef<HTMLUListElement>(null)
|
|
|
|
const bgClassName =
|
|
|
|
'group-enabled:group-hover:bg-energy-10 group-pressed:bg-energy-10 dark:group-enabled:group-hover:bg-chalkboard-80 dark:group-pressed:bg-chalkboard-80'
|
2024-02-19 17:23:03 +11:00
|
|
|
const pathId = useMemo(() => {
|
|
|
|
if (!isSingleCursorInPipe(context.selectionRanges, kclManager.ast)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return isCursorInSketchCommandRange(
|
|
|
|
engineCommandManager.artifactMap,
|
|
|
|
context.selectionRanges
|
|
|
|
)
|
|
|
|
}, [engineCommandManager.artifactMap, context.selectionRanges])
|
2023-10-04 12:35:50 -04:00
|
|
|
|
|
|
|
function handleToolbarButtonsWheelEvent(ev: WheelEvent<HTMLSpanElement>) {
|
|
|
|
const span = toolbarButtonsRef.current
|
|
|
|
if (!span) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
span.scrollLeft = span.scrollLeft += ev.deltaY
|
|
|
|
}
|
2023-02-12 10:56:45 +11:00
|
|
|
|
2023-12-06 14:44:13 -05:00
|
|
|
function ToolbarButtons({
|
|
|
|
className = '',
|
|
|
|
...props
|
|
|
|
}: React.HTMLAttributes<HTMLElement>) {
|
2023-08-31 09:47:59 -04:00
|
|
|
return (
|
2023-12-06 14:44:13 -05:00
|
|
|
<ul
|
|
|
|
{...props}
|
2023-10-04 12:35:50 -04:00
|
|
|
ref={toolbarButtonsRef}
|
|
|
|
onWheel={handleToolbarButtonsWheelEvent}
|
2023-12-06 14:44:13 -05:00
|
|
|
className={
|
|
|
|
'm-0 py-1 rounded-l-sm flex gap-2 items-center overflow-x-auto ' +
|
|
|
|
className
|
|
|
|
}
|
|
|
|
style={{ scrollbarWidth: 'thin' }}
|
2023-10-04 12:35:50 -04:00
|
|
|
>
|
2023-10-11 13:36:54 +11:00
|
|
|
{state.nextEvents.includes('Enter sketch') && (
|
2023-12-06 14:44:13 -05:00
|
|
|
<li className="contents">
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
2024-02-19 17:23:03 +11:00
|
|
|
onClick={() =>
|
|
|
|
send({ type: 'Enter sketch', data: { forceNewSketch: true } })
|
|
|
|
}
|
2023-12-06 14:44:13 -05:00
|
|
|
icon={{
|
|
|
|
icon: 'sketch',
|
|
|
|
bgClassName,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<span data-testid="start-sketch">Start Sketch</span>
|
|
|
|
</ActionButton>
|
|
|
|
</li>
|
2023-08-31 09:47:59 -04:00
|
|
|
)}
|
2023-10-11 13:36:54 +11:00
|
|
|
{state.nextEvents.includes('Enter sketch') && pathId && (
|
2023-12-06 14:44:13 -05:00
|
|
|
<li className="contents">
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
onClick={() => send({ type: 'Enter sketch' })}
|
|
|
|
icon={{
|
|
|
|
icon: 'sketch',
|
|
|
|
bgClassName,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Edit Sketch
|
|
|
|
</ActionButton>
|
|
|
|
</li>
|
2023-08-31 09:47:59 -04:00
|
|
|
)}
|
2023-10-11 13:36:54 +11:00
|
|
|
{state.nextEvents.includes('Cancel') && !state.matches('idle') && (
|
2023-12-06 14:44:13 -05:00
|
|
|
<li className="contents">
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
onClick={() => send({ type: 'Cancel' })}
|
|
|
|
icon={{
|
|
|
|
icon: 'arrowLeft',
|
|
|
|
bgClassName,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Exit Sketch
|
|
|
|
</ActionButton>
|
|
|
|
</li>
|
2023-10-11 13:36:54 +11:00
|
|
|
)}
|
|
|
|
{state.matches('Sketch') && !state.matches('idle') && (
|
2024-02-11 12:59:00 +11:00
|
|
|
<>
|
|
|
|
<li className="contents" key="line-button">
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
onClick={() =>
|
|
|
|
state?.matches('Sketch.Line tool')
|
|
|
|
? send('CancelSketch')
|
|
|
|
: send('Equip Line tool')
|
|
|
|
}
|
|
|
|
aria-pressed={state?.matches('Sketch.Line tool')}
|
|
|
|
className="pressed:bg-energy-10/20 dark:pressed:bg-energy-80"
|
|
|
|
icon={{
|
|
|
|
icon: 'line',
|
|
|
|
bgClassName,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Line
|
|
|
|
</ActionButton>
|
|
|
|
</li>
|
|
|
|
<li className="contents" key="tangential-arc-button">
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
onClick={() =>
|
|
|
|
state.matches('Sketch.Tangential arc to')
|
|
|
|
? send('CancelSketch')
|
|
|
|
: send('Equip tangential arc to')
|
|
|
|
}
|
|
|
|
aria-pressed={state.matches('Sketch.Tangential arc to')}
|
|
|
|
className="pressed:bg-energy-10/20 dark:pressed:bg-energy-80"
|
|
|
|
icon={{
|
2024-02-20 13:34:03 -05:00
|
|
|
icon: 'arc',
|
2024-02-11 12:59:00 +11:00
|
|
|
bgClassName,
|
|
|
|
}}
|
|
|
|
disabled={
|
|
|
|
!state.can('Equip tangential arc to') &&
|
|
|
|
!state.matches('Sketch.Tangential arc to')
|
|
|
|
}
|
|
|
|
>
|
|
|
|
Tangential Arc
|
|
|
|
</ActionButton>
|
|
|
|
</li>
|
|
|
|
</>
|
2023-08-31 09:47:59 -04:00
|
|
|
)}
|
2023-10-11 13:36:54 +11:00
|
|
|
{state.matches('Sketch.SketchIdle') &&
|
|
|
|
state.nextEvents
|
|
|
|
.filter(
|
|
|
|
(eventName) =>
|
|
|
|
eventName.includes('Make segment') ||
|
|
|
|
eventName.includes('Constrain')
|
2023-08-31 09:47:59 -04:00
|
|
|
)
|
2023-12-01 20:49:26 +11:00
|
|
|
.sort((a, b) => {
|
|
|
|
const aisEnabled = state.nextEvents
|
|
|
|
.filter((event) => state.can(event as any))
|
|
|
|
.includes(a)
|
|
|
|
const bIsEnabled = state.nextEvents
|
|
|
|
.filter((event) => state.can(event as any))
|
|
|
|
.includes(b)
|
|
|
|
if (aisEnabled && !bIsEnabled) {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
if (!aisEnabled && bIsEnabled) {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
})
|
2023-10-11 13:36:54 +11:00
|
|
|
.map((eventName) => (
|
2024-02-11 12:59:00 +11:00
|
|
|
<li className="contents" key={eventName}>
|
2023-12-06 14:44:13 -05:00
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
className="text-sm"
|
|
|
|
key={eventName}
|
|
|
|
onClick={() => send(eventName)}
|
|
|
|
disabled={
|
|
|
|
!state.nextEvents
|
|
|
|
.filter((event) => state.can(event as any))
|
|
|
|
.includes(eventName)
|
|
|
|
}
|
|
|
|
title={eventName}
|
|
|
|
icon={{
|
|
|
|
icon: 'line',
|
|
|
|
bgClassName,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{eventName
|
|
|
|
.replace('Make segment ', '')
|
|
|
|
.replace('Constrain ', '')}
|
|
|
|
</ActionButton>
|
|
|
|
</li>
|
2023-10-11 13:36:54 +11:00
|
|
|
))}
|
|
|
|
{state.matches('idle') && (
|
2023-12-06 14:44:13 -05:00
|
|
|
<li className="contents">
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
|
|
|
className="text-sm"
|
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
|
|
|
onClick={() =>
|
|
|
|
commandBarSend({
|
|
|
|
type: 'Find and select command',
|
|
|
|
data: { name: 'Extrude', ownerMachine: 'modeling' },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
disabled={!state.can('Extrude')}
|
2023-12-06 14:44:13 -05:00
|
|
|
title={
|
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
|
|
|
state.can('Extrude')
|
2023-12-06 14:44:13 -05:00
|
|
|
? 'extrude'
|
|
|
|
: 'sketches need to be closed, or not already extruded'
|
|
|
|
}
|
|
|
|
icon={{
|
|
|
|
icon: 'extrude',
|
|
|
|
bgClassName,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Extrude
|
|
|
|
</ActionButton>
|
|
|
|
</li>
|
2023-10-11 13:36:54 +11:00
|
|
|
)}
|
2023-12-06 14:44:13 -05:00
|
|
|
</ul>
|
2023-08-31 09:47:59 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-12-06 14:44:13 -05:00
|
|
|
<div className="max-w-full flex items-stretch rounded-l-sm rounded-r-full bg-chalkboard-10 dark:bg-chalkboard-100 relative">
|
|
|
|
<menu className="flex-1 pl-1 pr-2 py-0 overflow-hidden rounded-l-sm whitespace-nowrap bg-chalkboard-10 dark:bg-chalkboard-100 border-solid border border-energy-10 dark:border-chalkboard-90 border-r-0">
|
|
|
|
<ToolbarButtons />
|
|
|
|
</menu>
|
|
|
|
<ActionButton
|
|
|
|
Element="button"
|
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
|
|
|
onClick={() => commandBarSend({ type: 'Open' })}
|
2023-12-06 14:44:13 -05:00
|
|
|
className="rounded-r-full pr-4 self-stretch border-energy-10 hover:border-energy-10 dark:border-chalkboard-80 bg-energy-10/50 hover:bg-energy-10 dark:bg-chalkboard-80 dark:text-energy-10"
|
2023-08-31 09:47:59 -04:00
|
|
|
>
|
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
|
|
|
{platform === 'darwin' ? '⌘K' : 'Ctrl+/'}
|
2023-12-06 14:44:13 -05:00
|
|
|
</ActionButton>
|
|
|
|
</div>
|
2022-11-27 14:06:33 +11:00
|
|
|
)
|
|
|
|
}
|