Migrate to XState v5 (#3735)

* migrate settingsMachine

* Guard events with properties instead

* migrate settingsMachine

* Migrate auth machine

* Migrate file machine

* Migrate depracated types

* Migrate home machine

* Migrate command bar machine

* Version fixes

* Migrate command bar machine

* Migrate modeling machine

* Migrate types, state.can, state.matches and state.nextEvents

* Fix syntax

* Pass in modelingState into editor manager instead of modeling event

* Fix issue with missing command bar provider

* Fix state transition

* Fix type issue in Home

* Make sure no guards rely on event type

* Fix up command bar submission logic

* Home machine tweaks to get things running

* Fix AST fillet function args

* Handle "Set selection" when it is called by actor onDone

* Remove unused imports

* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)

* Fix injectin project to the fileTree machine

* Revert "A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)"

This reverts commit 4b43ff69d1.

* A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest)

* Re-run CI

* Restore success toasts on file/folder deletion

* Replace casting with guarding against event.type

* Remove console.log

Co-authored-by: Jonathan Tran <jonnytran@gmail.com>

* Replace all instances of event casting with guards against event.type

---------

Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
Co-authored-by: Frank Noirot <frank@zoo.dev>
This commit is contained in:
Farzad Yousefzadeh
2024-09-09 19:59:36 +03:00
committed by GitHub
parent 7c2cfba0ac
commit 5f8d4f8294
34 changed files with 3707 additions and 3139 deletions

View File

@ -16,7 +16,7 @@ type ToolbarMode = {
}
export interface ToolbarItemCallbackProps {
modelingStateMatches: StateFrom<typeof modelingMachine>['matches']
modelingState: StateFrom<typeof modelingMachine>
modelingSend: (event: EventFrom<typeof modelingMachine>) => void
commandBarSend: (event: EventFrom<typeof commandBarMachine>) => void
sketchPathId: string | false
@ -84,7 +84,7 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
type: 'Find and select command',
data: { name: 'Extrude', groupId: 'modeling' },
}),
disabled: (state) => !state.can('Extrude'),
disabled: (state) => !state.can({ type: 'Extrude' }),
icon: 'extrude',
status: 'available',
title: 'Extrude',
@ -155,7 +155,7 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
}),
icon: 'fillet3d',
status: DEV ? 'available' : 'kcl-only',
disabled: (state) => !state.can('Fillet'),
disabled: (state) => !state.can({ type: 'Fillet' }),
title: 'Fillet',
hotkey: 'F',
description: 'Round the edges of a 3D solid.',
@ -272,7 +272,7 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
}),
disableHotkey: (state) =>
!(
state.matches('Sketch.SketchIdle') ||
state.matches({ Sketch: 'SketchIdle' }) ||
state.matches('Sketch no face')
),
icon: 'arrowLeft',
@ -286,33 +286,37 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
'break',
{
id: 'line',
onClick: ({ modelingStateMatches: matches, modelingSend }) =>
onClick: ({ modelingState, modelingSend }) =>
modelingSend({
type: 'change tool',
data: {
tool: !matches('Sketch.Line tool') ? 'line' : 'none',
tool: !modelingState.matches({ Sketch: 'Line tool' })
? 'line'
: 'none',
},
}),
icon: 'line',
status: 'available',
disabled: (state) =>
state.matches('Sketch no face') ||
state.matches('Sketch.Rectangle tool.Awaiting second corner'),
state.matches({
Sketch: { 'Rectangle tool': 'Awaiting second corner' },
}),
title: 'Line',
hotkey: (state) =>
state.matches('Sketch.Line tool') ? ['Esc', 'L'] : 'L',
state.matches({ Sketch: 'Line tool' }) ? ['Esc', 'L'] : 'L',
description: 'Start drawing straight lines',
links: [],
isActive: (state) => state.matches('Sketch.Line tool'),
isActive: (state) => state.matches({ Sketch: 'Line tool' }),
},
[
{
id: 'tangential-arc',
onClick: ({ modelingStateMatches, modelingSend }) =>
onClick: ({ modelingState, modelingSend }) =>
modelingSend({
type: 'change tool',
data: {
tool: !modelingStateMatches('Sketch.Tangential arc to')
tool: !modelingState.matches({ Sketch: 'Tangential arc to' })
? 'tangentialArc'
: 'none',
},
@ -321,13 +325,13 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
status: 'available',
disabled: (state) =>
!isEditingExistingSketch(state.context) &&
!state.matches('Sketch.Tangential arc to'),
!state.matches({ Sketch: 'Tangential arc to' }),
title: 'Tangential Arc',
hotkey: (state) =>
state.matches('Sketch.Tangential arc to') ? ['Esc', 'A'] : 'A',
state.matches({ Sketch: 'Tangential arc to' }) ? ['Esc', 'A'] : 'A',
description: 'Start drawing an arc tangent to the current segment',
links: [],
isActive: (state) => state.matches('Sketch.Tangential arc to'),
isActive: (state) => state.matches({ Sketch: 'Tangential arc to' }),
},
{
id: 'three-point-arc',
@ -388,11 +392,11 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
[
{
id: 'corner-rectangle',
onClick: ({ modelingStateMatches, modelingSend }) =>
onClick: ({ modelingState, modelingSend }) =>
modelingSend({
type: 'change tool',
data: {
tool: !modelingStateMatches('Sketch.Rectangle tool')
tool: !modelingState.matches({ Sketch: 'Rectangle tool' })
? 'rectangle'
: 'none',
},
@ -401,13 +405,13 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
status: 'available',
disabled: (state) =>
!canRectangleTool(state.context) &&
!state.matches('Sketch.Rectangle tool'),
!state.matches({ Sketch: 'Rectangle tool' }),
title: 'Corner rectangle',
hotkey: (state) =>
state.matches('Sketch.Rectangle tool') ? ['Esc', 'R'] : 'R',
state.matches({ Sketch: 'Rectangle tool' }) ? ['Esc', 'R'] : 'R',
description: 'Start drawing a rectangle',
links: [],
isActive: (state) => state.matches('Sketch.Rectangle tool'),
isActive: (state) => state.matches({ Sketch: 'Rectangle tool' }),
},
{
id: 'center-rectangle',
@ -456,9 +460,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-length',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain length') &&
state.can('Constrain length')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain length' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain length' }),
@ -473,9 +476,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-angle',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain angle') &&
state.can('Constrain angle')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain angle' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain angle' }),
@ -489,9 +491,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-vertical',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Make segment vertical') &&
state.can('Make segment vertical')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Make segment vertical' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Make segment vertical' }),
@ -506,9 +507,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-horizontal',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Make segment horizontal') &&
state.can('Make segment horizontal')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Make segment horizontal' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Make segment horizontal' }),
@ -523,9 +523,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-parallel',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain parallel') &&
state.can('Constrain parallel')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain parallel' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain parallel' }),
@ -539,9 +538,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-equal-length',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain equal length') &&
state.can('Constrain equal length')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain equal length' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain equal length' }),
@ -555,9 +553,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-horizontal-distance',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain horizontal distance') &&
state.can('Constrain horizontal distance')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain horizontal distance' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain horizontal distance' }),
@ -571,9 +568,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-vertical-distance',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain vertical distance') &&
state.can('Constrain vertical distance')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain vertical distance' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain vertical distance' }),
@ -587,9 +583,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-absolute-x',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain ABS X') &&
state.can('Constrain ABS X')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain ABS X' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain ABS X' }),
@ -603,9 +598,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-absolute-y',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain ABS Y') &&
state.can('Constrain ABS Y')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain ABS Y' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain ABS Y' }),
@ -619,9 +613,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-perpendicular-distance',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain perpendicular distance') &&
state.can('Constrain perpendicular distance')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain perpendicular distance' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain perpendicular distance' }),
@ -636,9 +629,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-align-horizontal',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain horizontally align') &&
state.can('Constrain horizontally align')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain horizontally align' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain horizontally align' }),
@ -652,9 +644,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-align-vertical',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain vertically align') &&
state.can('Constrain vertically align')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain vertically align' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain vertically align' }),
@ -668,9 +659,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'snap-to-x',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain snap to X') &&
state.can('Constrain snap to X')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain snap to X' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain snap to X' }),
@ -684,9 +674,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'snap-to-y',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain snap to Y') &&
state.can('Constrain snap to Y')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain snap to Y' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain snap to Y' }),
@ -700,9 +689,8 @@ export const toolbarConfig: Record<ToolbarModeName, ToolbarMode> = {
id: 'constraint-remove',
disabled: (state) =>
!(
state.matches('Sketch.SketchIdle') &&
state.nextEvents.includes('Constrain remove constraints') &&
state.can('Constrain remove constraints')
state.matches({ Sketch: 'SketchIdle' }) &&
state.can({ type: 'Constrain remove constraints' })
),
onClick: ({ modelingSend }) =>
modelingSend({ type: 'Constrain remove constraints' }),