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'
|
2024-03-22 16:55:30 +11:00
|
|
|
import { engineCommandManager, kclManager } from 'lib/singletons'
|
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'
|
2024-02-19 17:23:03 +11:00
|
|
|
import { isSingleCursorInPipe } from 'lang/queryAst'
|
2024-03-22 16:55:30 +11:00
|
|
|
import { useKclContext } from 'lang/KclProvider'
|
2024-02-26 21:02:33 +11:00
|
|
|
import {
|
|
|
|
NetworkHealthState,
|
|
|
|
useNetworkStatus,
|
|
|
|
} from 'components/NetworkHealthIndicator'
|
|
|
|
import { useStore } from 'useStore'
|
2024-05-10 19:02:11 -04:00
|
|
|
import { ActionButtonDropdown } from 'components/ActionButtonDropdown'
|
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 { 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)
|
2024-04-05 00:59:02 -04:00
|
|
|
const iconClassName =
|
2024-05-10 19:02:11 -04:00
|
|
|
'group-disabled:text-chalkboard-50 group-enabled:group-hover:!text-primary dark:group-enabled:group-hover:!text-inherit group-pressed:!text-chalkboard-10 group-ui-open:!text-chalkboard-10 dark:group-ui-open:!text-chalkboard-10'
|
2023-12-06 14:44:13 -05:00
|
|
|
const bgClassName =
|
2024-05-10 19:02:11 -04:00
|
|
|
'group-disabled:!bg-transparent group-enabled:group-hover:bg-primary/10 dark:group-enabled:group-hover:bg-primary group-pressed:bg-primary group-ui-open:bg-primary'
|
2024-04-05 00:59:02 -04:00
|
|
|
const buttonClassName =
|
2024-05-10 19:02:11 -04:00
|
|
|
'bg-chalkboard-10 dark:bg-chalkboard-100 enabled:hover:bg-chalkboard-10 dark:enabled:hover:bg-chalkboard-100 pressed:!border-primary ui-open:!border-primary'
|
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])
|
2024-02-26 21:02:33 +11:00
|
|
|
const { overallState } = useNetworkStatus()
|
|
|
|
const { isExecuting } = useKclContext()
|
|
|
|
const { isStreamReady } = useStore((s) => ({
|
|
|
|
isStreamReady: s.isStreamReady,
|
|
|
|
}))
|
|
|
|
const disableAllButtons =
|
|
|
|
overallState !== NetworkHealthState.Ok || isExecuting || !isStreamReady
|
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}
|
2024-05-10 19:02:11 -04:00
|
|
|
className={'m-0 py-1 rounded-l-sm flex gap-2 items-center ' + className}
|
2023-12-06 14:44:13 -05:00
|
|
|
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
|
2024-04-05 00:59:02 -04:00
|
|
|
className={buttonClassName}
|
2023-12-06 14:44:13 -05:00
|
|
|
Element="button"
|
2024-02-19 17:23:03 +11:00
|
|
|
onClick={() =>
|
|
|
|
send({ type: 'Enter sketch', data: { forceNewSketch: true } })
|
|
|
|
}
|
2024-05-10 19:02:11 -04:00
|
|
|
iconStart={{
|
2023-12-06 14:44:13 -05:00
|
|
|
icon: 'sketch',
|
2024-04-05 00:59:02 -04:00
|
|
|
iconClassName,
|
2023-12-06 14:44:13 -05:00
|
|
|
bgClassName,
|
|
|
|
}}
|
2024-02-26 21:02:33 +11:00
|
|
|
disabled={disableAllButtons}
|
2023-12-06 14:44:13 -05:00
|
|
|
>
|
|
|
|
<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
|
2024-04-05 00:59:02 -04:00
|
|
|
className={buttonClassName}
|
2023-12-06 14:44:13 -05:00
|
|
|
Element="button"
|
|
|
|
onClick={() => send({ type: 'Enter sketch' })}
|
2024-05-10 19:02:11 -04:00
|
|
|
iconStart={{
|
2023-12-06 14:44:13 -05:00
|
|
|
icon: 'sketch',
|
2024-04-05 00:59:02 -04:00
|
|
|
iconClassName,
|
2023-12-06 14:44:13 -05:00
|
|
|
bgClassName,
|
|
|
|
}}
|
2024-02-26 21:02:33 +11:00
|
|
|
disabled={disableAllButtons}
|
2023-12-06 14:44:13 -05:00
|
|
|
>
|
|
|
|
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
|
2024-04-05 00:59:02 -04:00
|
|
|
className={buttonClassName}
|
2023-12-06 14:44:13 -05:00
|
|
|
Element="button"
|
|
|
|
onClick={() => send({ type: 'Cancel' })}
|
2024-05-10 19:02:11 -04:00
|
|
|
iconStart={{
|
2023-12-06 14:44:13 -05:00
|
|
|
icon: 'arrowLeft',
|
2024-04-05 00:59:02 -04:00
|
|
|
iconClassName,
|
2023-12-06 14:44:13 -05:00
|
|
|
bgClassName,
|
|
|
|
}}
|
2024-02-26 21:02:33 +11:00
|
|
|
disabled={disableAllButtons}
|
2023-12-06 14:44:13 -05:00
|
|
|
>
|
|
|
|
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
|
2024-04-05 00:59:02 -04:00
|
|
|
className={buttonClassName}
|
2024-02-11 12:59:00 +11:00
|
|
|
Element="button"
|
|
|
|
onClick={() =>
|
|
|
|
state?.matches('Sketch.Line tool')
|
|
|
|
? send('CancelSketch')
|
|
|
|
: send('Equip Line tool')
|
|
|
|
}
|
|
|
|
aria-pressed={state?.matches('Sketch.Line tool')}
|
2024-05-10 19:02:11 -04:00
|
|
|
iconStart={{
|
2024-02-11 12:59:00 +11:00
|
|
|
icon: 'line',
|
2024-04-05 00:59:02 -04:00
|
|
|
iconClassName,
|
2024-02-11 12:59:00 +11:00
|
|
|
bgClassName,
|
|
|
|
}}
|
2024-02-26 21:02:33 +11:00
|
|
|
disabled={disableAllButtons}
|
2024-02-11 12:59:00 +11:00
|
|
|
>
|
|
|
|
Line
|
|
|
|
</ActionButton>
|
|
|
|
</li>
|
|
|
|
<li className="contents" key="tangential-arc-button">
|
|
|
|
<ActionButton
|
2024-04-05 00:59:02 -04:00
|
|
|
className={buttonClassName}
|
2024-02-11 12:59:00 +11:00
|
|
|
Element="button"
|
|
|
|
onClick={() =>
|
|
|
|
state.matches('Sketch.Tangential arc to')
|
|
|
|
? send('CancelSketch')
|
|
|
|
: send('Equip tangential arc to')
|
|
|
|
}
|
|
|
|
aria-pressed={state.matches('Sketch.Tangential arc to')}
|
2024-05-10 19:02:11 -04:00
|
|
|
iconStart={{
|
2024-02-20 13:34:03 -05:00
|
|
|
icon: 'arc',
|
2024-04-05 00:59:02 -04:00
|
|
|
iconClassName,
|
2024-02-11 12:59:00 +11:00
|
|
|
bgClassName,
|
|
|
|
}}
|
|
|
|
disabled={
|
2024-02-26 21:02:33 +11:00
|
|
|
(!state.can('Equip tangential arc to') &&
|
|
|
|
!state.matches('Sketch.Tangential arc to')) ||
|
|
|
|
disableAllButtons
|
2024-02-11 12:59:00 +11:00
|
|
|
}
|
|
|
|
>
|
|
|
|
Tangential Arc
|
|
|
|
</ActionButton>
|
|
|
|
</li>
|
2024-04-19 11:56:21 -04:00
|
|
|
<li className="contents" key="rectangle-button">
|
|
|
|
<ActionButton
|
|
|
|
className={buttonClassName}
|
|
|
|
Element="button"
|
|
|
|
onClick={() =>
|
|
|
|
state.matches('Sketch.Rectangle tool')
|
|
|
|
? send('CancelSketch')
|
|
|
|
: send('Equip rectangle tool')
|
|
|
|
}
|
|
|
|
aria-pressed={state.matches('Sketch.Rectangle tool')}
|
2024-05-10 19:02:11 -04:00
|
|
|
iconStart={{
|
2024-04-19 11:56:21 -04:00
|
|
|
icon: 'rectangle',
|
|
|
|
iconClassName,
|
|
|
|
bgClassName,
|
|
|
|
}}
|
|
|
|
disabled={
|
|
|
|
(!state.can('Equip rectangle tool') &&
|
|
|
|
!state.matches('Sketch.Rectangle tool')) ||
|
|
|
|
disableAllButtons
|
|
|
|
}
|
|
|
|
title={
|
|
|
|
state.can('Equip rectangle tool')
|
|
|
|
? 'Rectangle'
|
|
|
|
: 'Can only be used when a sketch is empty currently'
|
|
|
|
}
|
|
|
|
>
|
|
|
|
Rectangle
|
|
|
|
</ActionButton>
|
|
|
|
</li>
|
2024-02-11 12:59:00 +11:00
|
|
|
</>
|
2023-08-31 09:47:59 -04:00
|
|
|
)}
|
2023-10-11 13:36:54 +11:00
|
|
|
{state.matches('Sketch.SketchIdle') &&
|
2024-05-10 19:02:11 -04:00
|
|
|
state.nextEvents.filter(
|
|
|
|
(eventName) =>
|
|
|
|
eventName.includes('Make segment') ||
|
|
|
|
eventName.includes('Constrain')
|
|
|
|
).length > 0 && (
|
|
|
|
<ActionButtonDropdown
|
|
|
|
splitMenuItems={state.nextEvents
|
|
|
|
.filter(
|
|
|
|
(eventName) =>
|
|
|
|
eventName.includes('Make segment') ||
|
|
|
|
eventName.includes('Constrain')
|
|
|
|
)
|
|
|
|
.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
|
2023-12-06 14:44:13 -05:00
|
|
|
}
|
2024-05-10 19:02:11 -04:00
|
|
|
if (!aisEnabled && bIsEnabled) {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
})
|
|
|
|
.map((eventName) => ({
|
|
|
|
label: eventName
|
2023-12-06 14:44:13 -05:00
|
|
|
.replace('Make segment ', '')
|
2024-05-10 19:02:11 -04:00
|
|
|
.replace('Constrain ', ''),
|
|
|
|
onClick: () => send(eventName),
|
|
|
|
disabled:
|
|
|
|
!state.nextEvents
|
|
|
|
.filter((event) => state.can(event as any))
|
|
|
|
.includes(eventName) || disableAllButtons,
|
|
|
|
}))}
|
|
|
|
className={buttonClassName}
|
|
|
|
Element="button"
|
|
|
|
iconStart={{
|
|
|
|
icon: 'dimension',
|
|
|
|
iconClassName,
|
|
|
|
bgClassName,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Constrain
|
|
|
|
</ActionButtonDropdown>
|
|
|
|
)}
|
2023-10-11 13:36:54 +11:00
|
|
|
{state.matches('idle') && (
|
2023-12-06 14:44:13 -05:00
|
|
|
<li className="contents">
|
|
|
|
<ActionButton
|
2024-04-05 00:59:02 -04:00
|
|
|
className={buttonClassName}
|
2023-12-06 14:44:13 -05:00
|
|
|
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: 'Find and select command',
|
|
|
|
data: { name: 'Extrude', ownerMachine: 'modeling' },
|
|
|
|
})
|
|
|
|
}
|
2024-02-26 21:02:33 +11:00
|
|
|
disabled={!state.can('Extrude') || disableAllButtons}
|
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'
|
|
|
|
}
|
2024-05-10 19:02:11 -04:00
|
|
|
iconStart={{
|
2023-12-06 14:44:13 -05:00
|
|
|
icon: 'extrude',
|
2024-04-05 00:59:02 -04:00
|
|
|
iconClassName,
|
2023-12-06 14:44:13 -05:00
|
|
|
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 (
|
2024-05-10 19:02:11 -04:00
|
|
|
<menu className="max-w-full whitespace-nowrap rounded px-1.5 py-0.5 backdrop-blur-sm bg-chalkboard-10/80 dark:bg-chalkboard-110/70 relative">
|
2024-05-08 09:57:16 -04:00
|
|
|
<ToolbarButtons />
|
|
|
|
</menu>
|
2022-11-27 14:06:33 +11:00
|
|
|
)
|
|
|
|
}
|