2024-03-14 15:56:45 -04:00
|
|
|
import {
|
2024-04-02 10:29:34 -04:00
|
|
|
Command,
|
|
|
|
CommandArgument,
|
|
|
|
CommandArgumentConfig,
|
|
|
|
} from '../commandTypes'
|
|
|
|
import {
|
|
|
|
SettingsPaths,
|
|
|
|
SettingsLevel,
|
|
|
|
SettingProps,
|
2024-03-14 15:56:45 -04:00
|
|
|
} from 'lib/settings/settingsTypes'
|
2024-03-12 10:37:35 -04:00
|
|
|
import { settingsMachine } from 'machines/settingsMachine'
|
2024-04-02 10:29:34 -04:00
|
|
|
import { PathValue } from 'lib/types'
|
|
|
|
import { AnyStateMachine, ContextFrom, InterpreterFrom } from 'xstate'
|
|
|
|
import { getPropertyByPath } from 'lib/objectPropertyByPath'
|
|
|
|
import { buildCommandArgument } from 'lib/createMachineCommand'
|
|
|
|
import decamelize from 'decamelize'
|
|
|
|
import { isTauri } from 'lib/isTauri'
|
2024-04-15 12:04:17 -04:00
|
|
|
import { Setting } from 'lib/settings/initialSettings'
|
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
|
|
|
|
2024-04-02 10:29:34 -04:00
|
|
|
// An array of the paths to all of the settings that have commandConfigs
|
|
|
|
export const settingsWithCommandConfigs = (
|
|
|
|
s: ContextFrom<typeof settingsMachine>
|
|
|
|
) =>
|
|
|
|
Object.entries(s).flatMap(([categoryName, categorySettings]) =>
|
|
|
|
Object.entries(categorySettings)
|
|
|
|
.filter(([_, setting]) => setting.commandConfig !== undefined)
|
|
|
|
.map(([settingName]) => `${categoryName}.${settingName}`)
|
|
|
|
) as SettingsPaths[]
|
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
|
|
|
|
2024-04-02 10:29:34 -04:00
|
|
|
const levelArgConfig = <T extends AnyStateMachine = AnyStateMachine>(
|
|
|
|
actor: InterpreterFrom<T>,
|
|
|
|
isProjectAvailable: boolean,
|
|
|
|
hideOnLevel?: SettingsLevel
|
|
|
|
): CommandArgument<SettingsLevel, T> => ({
|
|
|
|
inputType: 'options' as const,
|
|
|
|
required: true,
|
|
|
|
defaultValue:
|
|
|
|
isProjectAvailable && hideOnLevel !== 'project' ? 'project' : 'user',
|
|
|
|
skip: true,
|
|
|
|
options:
|
|
|
|
isProjectAvailable && hideOnLevel !== 'project'
|
|
|
|
? [
|
|
|
|
{ name: 'User', value: 'user' as SettingsLevel },
|
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
|
|
|
{
|
2024-04-02 10:29:34 -04:00
|
|
|
name: 'Project',
|
|
|
|
value: 'project' as SettingsLevel,
|
|
|
|
isCurrent: true,
|
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
|
|
|
},
|
2024-04-02 10:29:34 -04:00
|
|
|
]
|
|
|
|
: [{ name: 'User', value: 'user' as SettingsLevel, isCurrent: true }],
|
|
|
|
machineActor: actor,
|
|
|
|
})
|
|
|
|
|
|
|
|
interface CreateSettingsArgs {
|
|
|
|
type: SettingsPaths
|
|
|
|
send: Function
|
|
|
|
context: ContextFrom<typeof settingsMachine>
|
|
|
|
actor: InterpreterFrom<typeof settingsMachine>
|
|
|
|
isProjectAvailable: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
// Takes a Setting with a commandConfig and creates a Command
|
|
|
|
// that can be used in the CommandBar component.
|
|
|
|
export function createSettingsCommand({
|
|
|
|
type,
|
|
|
|
send,
|
|
|
|
context,
|
|
|
|
actor,
|
|
|
|
isProjectAvailable,
|
|
|
|
}: CreateSettingsArgs) {
|
|
|
|
type S = PathValue<typeof context, typeof type>
|
|
|
|
|
|
|
|
const settingConfig = getPropertyByPath(context, type) as SettingProps<
|
|
|
|
S['default']
|
|
|
|
>
|
|
|
|
const valueArgPartialConfig = settingConfig['commandConfig']
|
|
|
|
const shouldHideOnThisLevel =
|
|
|
|
settingConfig?.hideOnLevel === 'user' && !isProjectAvailable
|
|
|
|
const shouldHideOnThisPlatform =
|
|
|
|
settingConfig.hideOnPlatform &&
|
|
|
|
(isTauri()
|
|
|
|
? settingConfig.hideOnPlatform === 'desktop'
|
|
|
|
: settingConfig.hideOnPlatform === 'web')
|
|
|
|
if (
|
|
|
|
!valueArgPartialConfig ||
|
|
|
|
shouldHideOnThisLevel ||
|
|
|
|
shouldHideOnThisPlatform
|
|
|
|
)
|
|
|
|
return null
|
|
|
|
|
2024-04-15 12:04:17 -04:00
|
|
|
let valueArgConfig = {
|
2024-04-02 10:29:34 -04:00
|
|
|
...valueArgPartialConfig,
|
|
|
|
required: true,
|
|
|
|
} as CommandArgumentConfig<S['default']>
|
|
|
|
|
2024-04-15 12:04:17 -04:00
|
|
|
// If the setting is a boolean, we coerce it into an options input type
|
|
|
|
if (valueArgConfig.inputType === 'boolean') {
|
|
|
|
valueArgConfig = {
|
|
|
|
...valueArgConfig,
|
|
|
|
inputType: 'options',
|
|
|
|
options: (cmdBarContext, machineContext) => {
|
|
|
|
const setting = getPropertyByPath(
|
|
|
|
machineContext,
|
|
|
|
type
|
|
|
|
) as Setting<boolean>
|
|
|
|
const level = cmdBarContext.argumentsToSubmit.level as SettingsLevel
|
|
|
|
const isCurrent =
|
|
|
|
setting[level] === undefined
|
|
|
|
? setting.getFallback(level) === true
|
|
|
|
: setting[level] === true
|
|
|
|
return [
|
|
|
|
{ name: 'On', value: true, isCurrent },
|
|
|
|
{ name: 'Off', value: false, isCurrent: !isCurrent },
|
|
|
|
]
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-02 10:29:34 -04:00
|
|
|
// @ts-ignore - TODO figure out this typing for valueArgConfig
|
|
|
|
const valueArg = buildCommandArgument(valueArgConfig, context, actor)
|
|
|
|
|
|
|
|
const command: Command = {
|
|
|
|
name: type,
|
|
|
|
displayName: `Settings · ${decamelize(type.replaceAll('.', ' · '), {
|
|
|
|
separator: ' ',
|
|
|
|
})}`,
|
2024-07-12 17:48:38 -04:00
|
|
|
description: settingConfig.description,
|
2024-07-11 18:10:47 -04:00
|
|
|
groupId: 'settings',
|
2024-02-20 13:34:03 -05:00
|
|
|
icon: 'settings',
|
2024-04-02 10:29:34 -04:00
|
|
|
needsReview: false,
|
|
|
|
onSubmit: (data) => {
|
|
|
|
if (data !== undefined && data !== null) {
|
|
|
|
send({ type: `set.${type}`, data })
|
|
|
|
} else {
|
|
|
|
send(type)
|
|
|
|
}
|
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
|
|
|
},
|
|
|
|
args: {
|
2024-04-02 10:29:34 -04:00
|
|
|
level: levelArgConfig(
|
|
|
|
actor,
|
|
|
|
isProjectAvailable,
|
|
|
|
settingConfig.hideOnLevel
|
|
|
|
),
|
|
|
|
value: valueArg,
|
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
|
|
|
},
|
2024-04-02 10:29:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return command
|
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
|
|
|
}
|