Compare commits

...

1 Commits

Author SHA1 Message Date
8424355a07 xstate v5 rough start 2024-02-19 20:51:29 +11:00
14 changed files with 289 additions and 259 deletions

View File

@ -27,7 +27,7 @@
"@types/react-dom": "^18.0.0", "@types/react-dom": "^18.0.0",
"@uiw/react-codemirror": "^4.21.20", "@uiw/react-codemirror": "^4.21.20",
"@xstate/inspect": "^0.8.0", "@xstate/inspect": "^0.8.0",
"@xstate/react": "^3.2.2", "@xstate/react": "^4.1.0",
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"debounce-promise": "^3.1.2", "debounce-promise": "^3.1.2",
"formik": "^2.4.3", "formik": "^2.4.3",
@ -57,7 +57,7 @@
"wasm-pack": "^0.12.1", "wasm-pack": "^0.12.1",
"web-vitals": "^3.5.0", "web-vitals": "^3.5.0",
"ws": "^8.13.0", "ws": "^8.13.0",
"xstate": "^4.38.2", "xstate": "^5.7.1",
"zustand": "^4.4.5" "zustand": "^4.4.5"
}, },
"scripts": { "scripts": {

View File

@ -72,7 +72,7 @@ export function App() {
useHotkeys('shift + l', () => togglePane('logs')) useHotkeys('shift + l', () => togglePane('logs'))
useHotkeys('shift + e', () => togglePane('kclErrors')) useHotkeys('shift + e', () => togglePane('kclErrors'))
useHotkeys('shift + d', () => togglePane('debug')) useHotkeys('shift + d', () => togglePane('debug'))
useHotkeys('esc', () => send('Cancel')) useHotkeys('esc', () => send({ type: 'Cancel' }))
useHotkeys('backspace', (e) => { useHotkeys('backspace', (e) => {
e.preventDefault() e.preventDefault()
}) })

View File

@ -100,8 +100,8 @@ export const Toolbar = () => {
Element="button" Element="button"
onClick={() => onClick={() =>
state?.matches('Sketch.Line tool') state?.matches('Sketch.Line tool')
? send('CancelSketch') ? send({ type: 'CancelSketch' })
: send('Equip Line tool') : send({ type: 'Equip Line tool' })
} }
aria-pressed={state?.matches('Sketch.Line tool')} aria-pressed={state?.matches('Sketch.Line tool')}
className="pressed:bg-energy-10/20 dark:pressed:bg-energy-80" className="pressed:bg-energy-10/20 dark:pressed:bg-energy-80"
@ -118,8 +118,8 @@ export const Toolbar = () => {
Element="button" Element="button"
onClick={() => onClick={() =>
state.matches('Sketch.Tangential arc to') state.matches('Sketch.Tangential arc to')
? send('CancelSketch') ? send({ type: 'CancelSketch' })
: send('Equip tangential arc to') : send({ type: 'Equip tangential arc to' })
} }
aria-pressed={state.matches('Sketch.Tangential arc to')} aria-pressed={state.matches('Sketch.Tangential arc to')}
className="pressed:bg-energy-10/20 dark:pressed:bg-energy-80" className="pressed:bg-energy-10/20 dark:pressed:bg-energy-80"
@ -128,7 +128,7 @@ export const Toolbar = () => {
bgClassName, bgClassName,
}} }}
disabled={ disabled={
!state.can('Equip tangential arc to') && !state.can({ type: 'Equip tangential arc to' }) &&
!state.matches('Sketch.Tangential arc to') !state.matches('Sketch.Tangential arc to')
} }
> >
@ -194,9 +194,9 @@ export const Toolbar = () => {
data: { name: 'Extrude', ownerMachine: 'modeling' }, data: { name: 'Extrude', ownerMachine: 'modeling' },
}) })
} }
disabled={!state.can('Extrude')} disabled={!state.can({ type: 'Extrude' })}
title={ title={
state.can('Extrude') state.can({ type: 'Extrude' })
? 'extrude' ? 'extrude'
: 'sketches need to be closed, or not already extruded' : 'sketches need to be closed, or not already extruded'
} }

View File

@ -26,15 +26,16 @@ export const CommandBarProvider = ({
children: React.ReactNode children: React.ReactNode
}) => { }) => {
const { pathname } = useLocation() const { pathname } = useLocation()
const [commandBarState, commandBarSend] = useMachine(commandBarMachine, { const [commandBarState, commandBarSend] = useMachine(
commandBarMachine.provide({
guards: { guards: {
'Arguments are ready': (context, _) => { 'Arguments are ready': ({ context }) => {
return context.selectedCommand?.args return context.selectedCommand?.args
? context.argumentsToSubmit.length === ? context.argumentsToSubmit.length ===
Object.keys(context.selectedCommand.args)?.length Object.keys(context.selectedCommand.args)?.length
: false : false
}, },
'Command has no arguments': (context, _event) => { 'Command has no arguments': ({ context }) => {
return ( return (
!context.selectedCommand?.args || !context.selectedCommand?.args ||
Object.keys(context.selectedCommand?.args).length === 0 Object.keys(context.selectedCommand?.args).length === 0
@ -42,6 +43,7 @@ export const CommandBarProvider = ({
}, },
}, },
}) })
)
// Close the command bar when navigating // Close the command bar when navigating
useEffect(() => { useEffect(() => {

View File

@ -44,16 +44,14 @@ export const FileMachineProvider = ({
const { commandBarSend } = useCommandsContext() const { commandBarSend } = useCommandsContext()
const { project } = useRouteLoaderData(paths.FILE) as IndexLoaderData const { project } = useRouteLoaderData(paths.FILE) as IndexLoaderData
const [state, send] = useMachine(fileMachine, { const [state, send] = useMachine(
fileMachine.provide({
context: { context: {
project, project,
selectedDirectory: project, selectedDirectory: project,
}, },
actions: { actions: {
navigateToFile: ( navigateToFile: ({ context, event }) => {
context: ContextFrom<typeof fileMachine>,
event: EventFrom<typeof fileMachine>
) => {
if (event.data && 'name' in event.data) { if (event.data && 'name' in event.data) {
commandBarSend({ type: 'Close' }) commandBarSend({ type: 'Close' })
navigate( navigate(
@ -63,9 +61,9 @@ export const FileMachineProvider = ({
) )
} }
}, },
toastSuccess: (_, event) => toastSuccess: ({ event }) =>
event.data && toast.success((event.data || '') + ''), event.data && toast.success((event.data || '') + ''),
toastError: (_, event) => toast.error((event.data || '') + ''), toastError: ({ event }) => toast.error((event.data || '') + ''),
}, },
services: { services: {
readFiles: async (context: ContextFrom<typeof fileMachine>) => { readFiles: async (context: ContextFrom<typeof fileMachine>) => {
@ -136,12 +134,13 @@ export const FileMachineProvider = ({
}, },
}, },
guards: { guards: {
'Has at least 1 file': (_, event: EventFrom<typeof fileMachine>) => { 'Has at least 1 file': ({ event }) => {
if (event.type !== 'done.invoke.read-files') return false if (event.type !== 'done.invoke.read-files') return false
return !!event?.data?.children && event.data.children.length > 0 return !!event?.data?.children && event.data.children.length > 0
}, },
}, },
}) })
)
return ( return (
<FileContext.Provider <FileContext.Provider

View File

@ -85,7 +85,7 @@ export const ModelingMachineProvider = ({
'sketch exit execute': () => { 'sketch exit execute': () => {
kclManager.executeAst() kclManager.executeAst()
}, },
'Set selection': assign(({ selectionRanges }, event) => { 'Set selection': assign(({ context: { selectionRanges }, event }) => {
if (event.type !== 'Set selection') return {} // this was needed for ts after adding 'Set selection' action to on done modal events if (event.type !== 'Set selection') return {} // this was needed for ts after adding 'Set selection' action to on done modal events
const setSelections = event.data const setSelections = event.data
if (!editorView) return {} if (!editorView) return {}
@ -172,7 +172,7 @@ export const ModelingMachineProvider = ({
}), }),
}, },
guards: { guards: {
'has valid extrude selection': ({ selectionRanges }) => { 'has valid extrude selection': ({ context: { selectionRanges } }) => {
// A user can begin extruding if they either have 1+ faces selected or nothing selected // A user can begin extruding if they either have 1+ faces selected or nothing selected
// TODO: I believe this guard only allows for extruding a single face at a time // TODO: I believe this guard only allows for extruding a single face at a time
if (selectionRanges.codeBasedSelections.length < 1) return false if (selectionRanges.codeBasedSelections.length < 1) return false
@ -183,7 +183,10 @@ export const ModelingMachineProvider = ({
return canExtrudeSelection(selectionRanges) return canExtrudeSelection(selectionRanges)
}, },
'Selection is on face': ({ selectionRanges }, { data }) => { 'Selection is on face': ({
context: { selectionRanges },
event: { data },
}) => {
if (data?.forceNewSketch) return false if (data?.forceNewSketch) return false
if (!isSingleCursorInPipe(selectionRanges, kclManager.ast)) if (!isSingleCursorInPipe(selectionRanges, kclManager.ast))
return false return false
@ -194,7 +197,7 @@ export const ModelingMachineProvider = ({
}, },
}, },
services: { services: {
'AST-undo-startSketchOn': async ({ sketchPathToNode }) => { 'AST-undo-startSketchOn': async ({ context: { sketchPathToNode } }) => {
if (!sketchPathToNode) return if (!sketchPathToNode) return
const newAst: Program = JSON.parse(JSON.stringify(kclManager.ast)) const newAst: Program = JSON.parse(JSON.stringify(kclManager.ast))
const varDecIndex = sketchPathToNode[1][0] const varDecIndex = sketchPathToNode[1][0]
@ -206,7 +209,11 @@ export const ModelingMachineProvider = ({
onDrag: () => {}, onDrag: () => {},
}) })
}, },
'animate-to-face': async (_, { data: { plane, normal } }) => { 'animate-to-face': async ({
event: {
data: { plane, normal },
},
}) => {
const { modifiedAst, pathToNode } = startSketchOnDefault( const { modifiedAst, pathToNode } = startSketchOnDefault(
kclManager.ast, kclManager.ast,
plane plane
@ -220,8 +227,7 @@ export const ModelingMachineProvider = ({
} }
}, },
'animate-to-sketch': async ({ 'animate-to-sketch': async ({
sketchPathToNode, context: { sketchPathToNode, sketchNormalBackUp },
sketchNormalBackUp,
}) => { }) => {
const quaternion = getSketchQuaternion( const quaternion = getSketchQuaternion(
sketchPathToNode || [], sketchPathToNode || [],
@ -230,7 +236,7 @@ export const ModelingMachineProvider = ({
await sceneInfra.tweenCameraToQuaternion(quaternion) await sceneInfra.tweenCameraToQuaternion(quaternion)
}, },
'Get horizontal info': async ({ 'Get horizontal info': async ({
selectionRanges, context: { selectionRanges },
}): Promise<SetSelections> => { }): Promise<SetSelections> => {
const { modifiedAst, pathToNodeMap } = const { modifiedAst, pathToNodeMap } =
await applyConstraintHorzVertDistance({ await applyConstraintHorzVertDistance({
@ -248,7 +254,7 @@ export const ModelingMachineProvider = ({
} }
}, },
'Get vertical info': async ({ 'Get vertical info': async ({
selectionRanges, context: { selectionRanges },
}): Promise<SetSelections> => { }): Promise<SetSelections> => {
const { modifiedAst, pathToNodeMap } = const { modifiedAst, pathToNodeMap } =
await applyConstraintHorzVertDistance({ await applyConstraintHorzVertDistance({
@ -266,7 +272,7 @@ export const ModelingMachineProvider = ({
} }
}, },
'Get angle info': async ({ 'Get angle info': async ({
selectionRanges, context: { selectionRanges },
}): Promise<SetSelections> => { }): Promise<SetSelections> => {
const { modifiedAst, pathToNodeMap } = await (angleBetweenInfo({ const { modifiedAst, pathToNodeMap } = await (angleBetweenInfo({
selectionRanges, selectionRanges,
@ -289,7 +295,7 @@ export const ModelingMachineProvider = ({
} }
}, },
'Get length info': async ({ 'Get length info': async ({
selectionRanges, context: { selectionRanges },
}): Promise<SetSelections> => { }): Promise<SetSelections> => {
const { modifiedAst, pathToNodeMap } = const { modifiedAst, pathToNodeMap } =
await applyConstraintAngleLength({ selectionRanges }) await applyConstraintAngleLength({ selectionRanges })
@ -304,7 +310,7 @@ export const ModelingMachineProvider = ({
} }
}, },
'Get perpendicular distance info': async ({ 'Get perpendicular distance info': async ({
selectionRanges, context: { selectionRanges },
}): Promise<SetSelections> => { }): Promise<SetSelections> => {
const { modifiedAst, pathToNodeMap } = await applyConstraintIntersect( const { modifiedAst, pathToNodeMap } = await applyConstraintIntersect(
{ {
@ -322,7 +328,7 @@ export const ModelingMachineProvider = ({
} }
}, },
'Get ABS X info': async ({ 'Get ABS X info': async ({
selectionRanges, context: { selectionRanges },
}): Promise<SetSelections> => { }): Promise<SetSelections> => {
const { modifiedAst, pathToNodeMap } = const { modifiedAst, pathToNodeMap } =
await applyConstraintAbsDistance({ await applyConstraintAbsDistance({
@ -340,7 +346,7 @@ export const ModelingMachineProvider = ({
} }
}, },
'Get ABS Y info': async ({ 'Get ABS Y info': async ({
selectionRanges, context: { selectionRanges },
}): Promise<SetSelections> => { }): Promise<SetSelections> => {
const { modifiedAst, pathToNodeMap } = const { modifiedAst, pathToNodeMap } =
await applyConstraintAbsDistance({ await applyConstraintAbsDistance({
@ -358,7 +364,8 @@ export const ModelingMachineProvider = ({
} }
}, },
}, },
devTools: true, // TODO replace with inspect https://stately.ai/docs/inspector
// devTools: true,
} }
) )

View File

@ -81,7 +81,7 @@ export const authMachine = createMachine<UserContext, Events>(
'Log in': { 'Log in': {
target: 'checkIfLoggedIn', target: 'checkIfLoggedIn',
actions: assign({ actions: assign({
token: (_, event) => { token: ({ event }) => {
const token = event.token || '' const token = event.token || ''
localStorage.setItem(TOKEN_PERSIST_KEY, token) localStorage.setItem(TOKEN_PERSIST_KEY, token)
return token return token
@ -91,8 +91,7 @@ export const authMachine = createMachine<UserContext, Events>(
}, },
}, },
}, },
schema: { events: {} as { type: 'Log out' } | { type: 'Log in' } }, types: { events: {} as { type: 'Log out' } | { type: 'Log in' } },
predictableActionArguments: true,
preserveActionOrder: true, preserveActionOrder: true,
context: { context: {
token: persistedToken, token: persistedToken,

View File

@ -43,14 +43,14 @@ export const commandBarMachine = createMachine(
actions: [ actions: [
assign({ assign({
commands: (context, event) => commands: ({ context, event }) =>
[...context.commands, ...event.data.commands].sort( [...context.commands, ...event.data.commands].sort(
sortCommands sortCommands
), ),
}), }),
], ],
internal: true, reenter: false,
}, },
'Remove commands': { 'Remove commands': {
@ -58,7 +58,7 @@ export const commandBarMachine = createMachine(
actions: [ actions: [
assign({ assign({
commands: (context, event) => commands: ({ context, event }) =>
context.commands.filter( context.commands.filter(
(c) => (c) =>
!event.data.commands.some( !event.data.commands.some(
@ -70,7 +70,7 @@ export const commandBarMachine = createMachine(
}), }),
], ],
internal: true, reenter: false,
}, },
}, },
}, },
@ -88,7 +88,7 @@ export const commandBarMachine = createMachine(
always: [ always: [
{ {
target: 'Closed', target: 'Closed',
cond: 'Command has no arguments', guard: 'Command has no arguments',
actions: ['Execute command'], actions: ['Execute command'],
}, },
{ {
@ -116,7 +116,7 @@ export const commandBarMachine = createMachine(
target: '#Command Bar.Checking Arguments', target: '#Command Bar.Checking Arguments',
actions: [ actions: [
assign({ assign({
argumentsToSubmit: (context, event) => { argumentsToSubmit: ({ context, event }) => {
const [argName, argData] = Object.entries(event.data)[0] const [argName, argData] = Object.entries(event.data)[0]
const { currentArgument } = context const { currentArgument } = context
if (!currentArgument) return {} if (!currentArgument) return {}
@ -142,7 +142,7 @@ export const commandBarMachine = createMachine(
on: { on: {
'Change current argument': { 'Change current argument': {
target: 'Gathering arguments', target: 'Gathering arguments',
internal: true, reenter: false,
actions: ['Set current argument'], actions: ['Set current argument'],
}, },
@ -174,7 +174,7 @@ export const commandBarMachine = createMachine(
target: 'Review', target: 'Review',
actions: [ actions: [
assign({ assign({
argumentsToSubmit: (context, event) => { argumentsToSubmit: ({ context, event }) => {
const argName = Object.keys(event.data)[0] const argName = Object.keys(event.data)[0]
const { argumentsToSubmit } = context const { argumentsToSubmit } = context
const newArgumentsToSubmit = { ...argumentsToSubmit } const newArgumentsToSubmit = { ...argumentsToSubmit }
@ -199,7 +199,7 @@ export const commandBarMachine = createMachine(
onDone: [ onDone: [
{ {
target: 'Review', target: 'Review',
cond: 'Command needs review', guard: 'Command needs review',
}, },
{ {
target: 'Closed', target: 'Closed',
@ -222,11 +222,11 @@ export const commandBarMachine = createMachine(
Clear: { Clear: {
target: '#Command Bar', target: '#Command Bar',
internal: true, reenter: false,
actions: ['Clear argument data'], actions: ['Clear argument data'],
}, },
}, },
schema: { types: {
events: {} as events: {} as
| { type: 'Open' } | { type: 'Open' }
| { type: 'Close' } | { type: 'Close' }
@ -275,7 +275,6 @@ export const commandBarMachine = createMachine(
data: { arg: CommandArgumentWithName<unknown> } data: { arg: CommandArgumentWithName<unknown> }
}, },
}, },
predictableActionArguments: true,
preserveActionOrder: true, preserveActionOrder: true,
}, },
{ {

View File

@ -143,7 +143,7 @@ export const fileMachine = createMachine(
}, },
}, },
schema: { types: {
events: {} as events: {} as
| { type: 'Open file'; data: { name: string } } | { type: 'Open file'; data: { name: string } }
| { | {
@ -161,7 +161,6 @@ export const fileMachine = createMachine(
| { type: 'assign'; data: { [key: string]: any } }, | { type: 'assign'; data: { [key: string]: any } },
}, },
predictableActionArguments: true,
preserveActionOrder: true, preserveActionOrder: true,
tsTypes: {} as import('./fileMachine.typegen').Typegen0, tsTypes: {} as import('./fileMachine.typegen').Typegen0,
}, },

View File

@ -136,7 +136,7 @@ export const homeMachine = createMachine(
}, },
}, },
schema: { types: {
events: {} as events: {} as
| { type: 'Open project'; data: HomeCommandSchema['Open project'] } | { type: 'Open project'; data: HomeCommandSchema['Open project'] }
| { type: 'Rename project'; data: HomeCommandSchema['Rename project'] } | { type: 'Rename project'; data: HomeCommandSchema['Rename project'] }
@ -150,7 +150,6 @@ export const homeMachine = createMachine(
| { type: 'assign'; data: { [key: string]: any } }, | { type: 'assign'; data: { [key: string]: any } },
}, },
predictableActionArguments: true,
preserveActionOrder: true, preserveActionOrder: true,
tsTypes: {} as import('./homeMachine.typegen').Typegen0, tsTypes: {} as import('./homeMachine.typegen').Typegen0,
}, },

View File

@ -123,7 +123,6 @@ export const modelingMachine = createMachine(
id: 'Modeling', id: 'Modeling',
tsTypes: {} as import('./modelingMachine.typegen').Typegen0, tsTypes: {} as import('./modelingMachine.typegen').Typegen0,
predictableActionArguments: true,
preserveActionOrder: true, preserveActionOrder: true,
context: { context: {
@ -142,7 +141,7 @@ export const modelingMachine = createMachine(
moveDescs: [] as MoveDesc[], moveDescs: [] as MoveDesc[],
}, },
schema: { types: {
events: {} as ModelingMachineEvent, events: {} as ModelingMachineEvent,
}, },
@ -151,14 +150,14 @@ export const modelingMachine = createMachine(
on: { on: {
'Set selection': { 'Set selection': {
target: 'idle', target: 'idle',
internal: true, reenter: false,
actions: 'Set selection', actions: 'Set selection',
}, },
'Enter sketch': [ 'Enter sketch': [
{ {
target: 'animating to existing sketch', target: 'animating to existing sketch',
cond: 'Selection is on face', guard: 'Selection is on face',
actions: ['set sketch metadata'], actions: ['set sketch metadata'],
}, },
'Sketch no face', 'Sketch no face',
@ -166,9 +165,9 @@ export const modelingMachine = createMachine(
Extrude: { Extrude: {
target: 'idle', target: 'idle',
cond: 'has valid extrude selection', guard: 'has valid extrude selection',
actions: ['AST extrude'], actions: ['AST extrude'],
internal: true, reenter: false,
}, },
}, },
@ -181,111 +180,111 @@ export const modelingMachine = createMachine(
on: { on: {
'Set selection': { 'Set selection': {
target: 'SketchIdle', target: 'SketchIdle',
internal: true, reenter: false,
actions: 'Set selection', actions: 'Set selection',
}, },
'Make segment vertical': { 'Make segment vertical': {
cond: 'Can make selection vertical', guard: 'Can make selection vertical',
target: 'SketchIdle', target: 'SketchIdle',
internal: true, reenter: false,
actions: ['Make selection vertical'], actions: ['Make selection vertical'],
}, },
'Make segment horizontal': { 'Make segment horizontal': {
target: 'SketchIdle', target: 'SketchIdle',
internal: true, reenter: false,
cond: 'Can make selection horizontal', guard: 'Can make selection horizontal',
actions: ['Make selection horizontal'], actions: ['Make selection horizontal'],
}, },
'Constrain horizontal distance': { 'Constrain horizontal distance': {
target: 'Await horizontal distance info', target: 'Await horizontal distance info',
cond: 'Can constrain horizontal distance', guard: 'Can constrain horizontal distance',
}, },
'Constrain vertical distance': { 'Constrain vertical distance': {
target: 'Await vertical distance info', target: 'Await vertical distance info',
cond: 'Can constrain vertical distance', guard: 'Can constrain vertical distance',
}, },
'Constrain ABS X': { 'Constrain ABS X': {
target: 'Await ABS X info', target: 'Await ABS X info',
cond: 'Can constrain ABS X', guard: 'Can constrain ABS X',
}, },
'Constrain ABS Y': { 'Constrain ABS Y': {
target: 'Await ABS Y info', target: 'Await ABS Y info',
cond: 'Can constrain ABS Y', guard: 'Can constrain ABS Y',
}, },
'Constrain angle': { 'Constrain angle': {
target: 'Await angle info', target: 'Await angle info',
cond: 'Can constrain angle', guard: 'Can constrain angle',
}, },
'Constrain length': { 'Constrain length': {
target: 'Await length info', target: 'Await length info',
cond: 'Can constrain length', guard: 'Can constrain length',
}, },
'Constrain perpendicular distance': { 'Constrain perpendicular distance': {
target: 'Await perpendicular distance info', target: 'Await perpendicular distance info',
cond: 'Can constrain perpendicular distance', guard: 'Can constrain perpendicular distance',
}, },
'Constrain horizontally align': { 'Constrain horizontally align': {
cond: 'Can constrain horizontally align', guard: 'Can constrain horizontally align',
target: 'SketchIdle', target: 'SketchIdle',
internal: true, reenter: false,
actions: ['Constrain horizontally align'], actions: ['Constrain horizontally align'],
}, },
'Constrain vertically align': { 'Constrain vertically align': {
cond: 'Can constrain vertically align', guard: 'Can constrain vertically align',
target: 'SketchIdle', target: 'SketchIdle',
internal: true, reenter: false,
actions: ['Constrain vertically align'], actions: ['Constrain vertically align'],
}, },
'Constrain snap to X': { 'Constrain snap to X': {
cond: 'Can constrain snap to X', guard: 'Can constrain snap to X',
target: 'SketchIdle', target: 'SketchIdle',
internal: true, reenter: false,
actions: ['Constrain snap to X'], actions: ['Constrain snap to X'],
}, },
'Constrain snap to Y': { 'Constrain snap to Y': {
cond: 'Can constrain snap to Y', guard: 'Can constrain snap to Y',
target: 'SketchIdle', target: 'SketchIdle',
internal: true, reenter: false,
actions: ['Constrain snap to Y'], actions: ['Constrain snap to Y'],
}, },
'Constrain equal length': { 'Constrain equal length': {
cond: 'Can constrain equal length', guard: 'Can constrain equal length',
target: 'SketchIdle', target: 'SketchIdle',
internal: true, reenter: false,
actions: ['Constrain equal length'], actions: ['Constrain equal length'],
}, },
'Constrain parallel': { 'Constrain parallel': {
target: 'SketchIdle', target: 'SketchIdle',
internal: true, reenter: false,
cond: 'Can canstrain parallel', guard: 'Can canstrain parallel',
actions: ['Constrain parallel'], actions: ['Constrain parallel'],
}, },
'Constrain remove constraints': { 'Constrain remove constraints': {
target: 'SketchIdle', target: 'SketchIdle',
internal: true, reenter: false,
cond: 'Can constrain remove constraints', guard: 'Can constrain remove constraints',
actions: ['Constrain remove constraints'], actions: ['Constrain remove constraints'],
}, },
'Re-execute': { 'Re-execute': {
target: 'SketchIdle', target: 'SketchIdle',
internal: true, reenter: false,
actions: ['set sketchMetadata from pathToNode'], actions: ['set sketchMetadata from pathToNode'],
}, },
@ -293,7 +292,7 @@ export const modelingMachine = createMachine(
'Equip tangential arc to': { 'Equip tangential arc to': {
target: 'Tangential arc to', target: 'Tangential arc to',
cond: 'is editing existing sketch', guard: 'is editing existing sketch',
}, },
}, },
@ -394,12 +393,12 @@ export const modelingMachine = createMachine(
'Set selection': { 'Set selection': {
target: 'Line tool', target: 'Line tool',
description: `This is just here to stop one of the higher level "Set selections" firing when we are just trying to set the IDE code without triggering a full engine-execute`, description: `This is just here to stop one of the higher level "Set selections" firing when we are just trying to set the IDE code without triggering a full engine-execute`,
internal: true, reenter: false,
}, },
'Equip tangential arc to': { 'Equip tangential arc to': {
target: 'Tangential arc to', target: 'Tangential arc to',
cond: 'is editing existing sketch', guard: 'is editing existing sketch',
}, },
}, },
@ -408,7 +407,7 @@ export const modelingMachine = createMachine(
always: [ always: [
{ {
target: 'normal', target: 'normal',
cond: 'is editing existing sketch', guard: 'is editing existing sketch',
actions: 'set up draft line', actions: 'set up draft line',
}, },
'No Points', 'No Points',
@ -419,7 +418,7 @@ export const modelingMachine = createMachine(
on: { on: {
'Set selection': { 'Set selection': {
target: 'normal', target: 'normal',
internal: true, reenter: false,
}, },
}, },
}, },
@ -445,7 +444,7 @@ export const modelingMachine = createMachine(
always: [ always: [
{ {
target: 'SketchIdle', target: 'SketchIdle',
cond: 'is editing existing sketch', guard: 'is editing existing sketch',
}, },
'Line tool', 'Line tool',
], ],
@ -457,7 +456,7 @@ export const modelingMachine = createMachine(
on: { on: {
'Set selection': { 'Set selection': {
target: 'Tangential arc to', target: 'Tangential arc to',
internal: true, reenter: false,
}, },
'Equip Line tool': 'Line tool', 'Equip Line tool': 'Line tool',
@ -514,7 +513,7 @@ export const modelingMachine = createMachine(
on: { on: {
'Set selection': { 'Set selection': {
target: 'animating to plane', target: 'animating to plane',
internal: true, reenter: false,
}, },
}, },
}, },
@ -542,14 +541,14 @@ export const modelingMachine = createMachine(
'Set selection': { 'Set selection': {
target: '#Modeling', target: '#Modeling',
internal: true, reenter: false,
actions: 'Set selection', actions: 'Set selection',
}, },
}, },
}, },
{ {
guards: { guards: {
'is editing existing sketch': ({ sketchPathToNode }) => { 'is editing existing sketch': ({ context: { sketchPathToNode } }) => {
// should check that the variable declaration is a pipeExpression // should check that the variable declaration is a pipeExpression
// and that the pipeExpression contains a "startProfileAt" callExpression // and that the pipeExpression contains a "startProfileAt" callExpression
if (!sketchPathToNode) return false if (!sketchPathToNode) return false
@ -568,50 +567,53 @@ export const modelingMachine = createMachine(
) )
return hasStartProfileAt && pipeExpression.body.length > 2 return hasStartProfileAt && pipeExpression.body.length > 2
}, },
'Can make selection horizontal': ({ selectionRanges }) => 'Can make selection horizontal': ({ context: { selectionRanges } }) =>
horzVertInfo(selectionRanges, 'horizontal').enabled, horzVertInfo(selectionRanges, 'horizontal').enabled,
'Can make selection vertical': ({ selectionRanges }) => 'Can make selection vertical': ({ context: { selectionRanges } }) =>
horzVertInfo(selectionRanges, 'vertical').enabled, horzVertInfo(selectionRanges, 'vertical').enabled,
'Can constrain horizontal distance': ({ selectionRanges }) => 'Can constrain horizontal distance': ({ context: { selectionRanges } }) =>
horzVertDistanceInfo({ selectionRanges, constraint: 'setHorzDistance' }) horzVertDistanceInfo({ selectionRanges, constraint: 'setHorzDistance' })
.enabled, .enabled,
'Can constrain vertical distance': ({ selectionRanges }) => 'Can constrain vertical distance': ({ context: { selectionRanges } }) =>
horzVertDistanceInfo({ selectionRanges, constraint: 'setVertDistance' }) horzVertDistanceInfo({ selectionRanges, constraint: 'setVertDistance' })
.enabled, .enabled,
'Can constrain ABS X': ({ selectionRanges }) => 'Can constrain ABS X': ({ context: { selectionRanges } }) =>
absDistanceInfo({ selectionRanges, constraint: 'xAbs' }).enabled, absDistanceInfo({ selectionRanges, constraint: 'xAbs' }).enabled,
'Can constrain ABS Y': ({ selectionRanges }) => 'Can constrain ABS Y': ({ context: { selectionRanges } }) =>
absDistanceInfo({ selectionRanges, constraint: 'yAbs' }).enabled, absDistanceInfo({ selectionRanges, constraint: 'yAbs' }).enabled,
'Can constrain angle': ({ selectionRanges }) => 'Can constrain angle': ({ context: { selectionRanges } }) =>
angleBetweenInfo({ selectionRanges }).enabled || angleBetweenInfo({ selectionRanges }).enabled ||
angleLengthInfo({ selectionRanges, angleOrLength: 'setAngle' }).enabled, angleLengthInfo({ selectionRanges, angleOrLength: 'setAngle' }).enabled,
'Can constrain length': ({ selectionRanges }) => 'Can constrain length': ({ context: { selectionRanges } }) =>
angleLengthInfo({ selectionRanges }).enabled, angleLengthInfo({ selectionRanges }).enabled,
'Can constrain perpendicular distance': ({ selectionRanges }) => 'Can constrain perpendicular distance': ({
intersectInfo({ selectionRanges }).enabled, context: { selectionRanges },
'Can constrain horizontally align': ({ selectionRanges }) => }) => intersectInfo({ selectionRanges }).enabled,
'Can constrain horizontally align': ({ context: { selectionRanges } }) =>
horzVertDistanceInfo({ selectionRanges, constraint: 'setHorzDistance' }) horzVertDistanceInfo({ selectionRanges, constraint: 'setHorzDistance' })
.enabled, .enabled,
'Can constrain vertically align': ({ selectionRanges }) => 'Can constrain vertically align': ({ context: { selectionRanges } }) =>
horzVertDistanceInfo({ selectionRanges, constraint: 'setHorzDistance' }) horzVertDistanceInfo({ selectionRanges, constraint: 'setHorzDistance' })
.enabled, .enabled,
'Can constrain snap to X': ({ selectionRanges }) => 'Can constrain snap to X': ({ context: { selectionRanges } }) =>
absDistanceInfo({ selectionRanges, constraint: 'snapToXAxis' }).enabled, absDistanceInfo({ selectionRanges, constraint: 'snapToXAxis' }).enabled,
'Can constrain snap to Y': ({ selectionRanges }) => 'Can constrain snap to Y': ({ context: { selectionRanges } }) =>
absDistanceInfo({ selectionRanges, constraint: 'snapToYAxis' }).enabled, absDistanceInfo({ selectionRanges, constraint: 'snapToYAxis' }).enabled,
'Can constrain equal length': ({ selectionRanges }) => 'Can constrain equal length': ({ context: { selectionRanges } }) =>
setEqualLengthInfo({ selectionRanges }).enabled, setEqualLengthInfo({ selectionRanges }).enabled,
'Can canstrain parallel': ({ selectionRanges }) => 'Can canstrain parallel': ({ context: { selectionRanges } }) =>
equalAngleInfo({ selectionRanges }).enabled, equalAngleInfo({ selectionRanges }).enabled,
'Can constrain remove constraints': ({ selectionRanges }) => 'Can constrain remove constraints': ({ context: { selectionRanges } }) =>
removeConstrainingValuesInfo({ selectionRanges }).enabled, removeConstrainingValuesInfo({ selectionRanges }).enabled,
}, },
// end guards // end guards
actions: { actions: {
'set sketchMetadata from pathToNode': assign(({ sketchPathToNode }) => { 'set sketchMetadata from pathToNode': assign(
({ context: { sketchPathToNode } }) => {
if (!sketchPathToNode) return {} if (!sketchPathToNode) return {}
return getSketchMetadataFromPathToNode(sketchPathToNode) return getSketchMetadataFromPathToNode(sketchPathToNode)
}), }
),
'hide default planes': () => { 'hide default planes': () => {
sceneInfra.removeDefaultPlanes() sceneInfra.removeDefaultPlanes()
kclManager.hidePlanes() kclManager.hidePlanes()
@ -621,7 +623,7 @@ export const modelingMachine = createMachine(
sketchEnginePathId: '', sketchEnginePathId: '',
sketchPlaneId: '', sketchPlaneId: '',
}), }),
'set sketch metadata': assign(({ selectionRanges }) => { 'set sketch metadata': assign(({ context: { selectionRanges } }) => {
const sourceRange = selectionRanges.codeBasedSelections[0].range const sourceRange = selectionRanges.codeBasedSelections[0].range
const sketchPathToNode = getNodePathFromSourceRange( const sketchPathToNode = getNodePathFromSourceRange(
kclManager.ast, kclManager.ast,
@ -632,10 +634,12 @@ export const modelingMachine = createMachine(
selectionRanges selectionRanges
) )
}), }),
'set new sketch metadata': assign((_, { data }) => data), 'set new sketch metadata': assign(({ event: { data } }) => data),
// TODO implement source ranges for all of these constraints // TODO implement source ranges for all of these constraints
// need to make the async like the modal constraints // need to make the async like the modal constraints
'Make selection horizontal': ({ selectionRanges, sketchPathToNode }) => { 'Make selection horizontal': ({
context: { selectionRanges, sketchPathToNode },
}) => {
const { modifiedAst } = applyConstraintHorzVert( const { modifiedAst } = applyConstraintHorzVert(
selectionRanges, selectionRanges,
'horizontal', 'horizontal',
@ -647,7 +651,9 @@ export const modelingMachine = createMachine(
modifiedAst modifiedAst
) )
}, },
'Make selection vertical': ({ selectionRanges, sketchPathToNode }) => { 'Make selection vertical': ({
context: { selectionRanges, sketchPathToNode },
}) => {
const { modifiedAst } = applyConstraintHorzVert( const { modifiedAst } = applyConstraintHorzVert(
selectionRanges, selectionRanges,
'vertical', 'vertical',
@ -660,8 +666,7 @@ export const modelingMachine = createMachine(
) )
}, },
'Constrain horizontally align': ({ 'Constrain horizontally align': ({
selectionRanges, context: { selectionRanges, sketchPathToNode },
sketchPathToNode,
}) => { }) => {
const { modifiedAst } = applyConstraintHorzVertAlign({ const { modifiedAst } = applyConstraintHorzVertAlign({
selectionRanges, selectionRanges,
@ -672,7 +677,9 @@ export const modelingMachine = createMachine(
modifiedAst modifiedAst
) )
}, },
'Constrain vertically align': ({ selectionRanges, sketchPathToNode }) => { 'Constrain vertically align': ({
context: { selectionRanges, sketchPathToNode },
}) => {
const { modifiedAst } = applyConstraintHorzVertAlign({ const { modifiedAst } = applyConstraintHorzVertAlign({
selectionRanges, selectionRanges,
constraint: 'setHorzDistance', constraint: 'setHorzDistance',
@ -682,7 +689,9 @@ export const modelingMachine = createMachine(
modifiedAst modifiedAst
) )
}, },
'Constrain snap to X': ({ selectionRanges, sketchPathToNode }) => { 'Constrain snap to X': ({
context: { selectionRanges, sketchPathToNode },
}) => {
const { modifiedAst } = applyConstraintAxisAlign({ const { modifiedAst } = applyConstraintAxisAlign({
selectionRanges, selectionRanges,
constraint: 'snapToXAxis', constraint: 'snapToXAxis',
@ -692,7 +701,9 @@ export const modelingMachine = createMachine(
modifiedAst modifiedAst
) )
}, },
'Constrain snap to Y': ({ selectionRanges, sketchPathToNode }) => { 'Constrain snap to Y': ({
context: { selectionRanges, sketchPathToNode },
}) => {
const { modifiedAst } = applyConstraintAxisAlign({ const { modifiedAst } = applyConstraintAxisAlign({
selectionRanges, selectionRanges,
constraint: 'snapToYAxis', constraint: 'snapToYAxis',
@ -702,7 +713,9 @@ export const modelingMachine = createMachine(
modifiedAst modifiedAst
) )
}, },
'Constrain equal length': ({ selectionRanges, sketchPathToNode }) => { 'Constrain equal length': ({
context: { selectionRanges, sketchPathToNode },
}) => {
const { modifiedAst } = applyConstraintEqualLength({ const { modifiedAst } = applyConstraintEqualLength({
selectionRanges, selectionRanges,
}) })
@ -711,7 +724,9 @@ export const modelingMachine = createMachine(
modifiedAst modifiedAst
) )
}, },
'Constrain parallel': ({ selectionRanges, sketchPathToNode }) => { 'Constrain parallel': ({
context: { selectionRanges, sketchPathToNode },
}) => {
const { modifiedAst } = applyConstraintEqualAngle({ const { modifiedAst } = applyConstraintEqualAngle({
selectionRanges, selectionRanges,
}) })
@ -721,8 +736,7 @@ export const modelingMachine = createMachine(
) )
}, },
'Constrain remove constraints': ({ 'Constrain remove constraints': ({
selectionRanges, context: { selectionRanges, sketchPathToNode },
sketchPathToNode,
}) => { }) => {
const { modifiedAst } = applyRemoveConstrainingValues({ const { modifiedAst } = applyRemoveConstrainingValues({
selectionRanges, selectionRanges,
@ -732,7 +746,7 @@ export const modelingMachine = createMachine(
modifiedAst modifiedAst
) )
}, },
'AST extrude': (_, event) => { 'AST extrude': ({ event }) => {
if (!event.data) return if (!event.data) return
const { selection, distance } = event.data const { selection, distance } = event.data
const pathToNode = getNodePathFromSourceRange( const pathToNode = getNodePathFromSourceRange(
@ -750,12 +764,15 @@ export const modelingMachine = createMachine(
focusPath: pathToExtrudeArg, focusPath: pathToExtrudeArg,
}) })
}, },
'conditionally equip line tool': (_, { type }) => { 'conditionally equip line tool': ({ event: { type } }) => {
if (type === 'done.invoke.animate-to-face') { if (type === 'done.invoke.animate-to-face') {
sceneInfra.modelingSend('Equip Line tool') sceneInfra.modelingSend('Equip Line tool')
} }
}, },
'setup client side sketch segments': ({ sketchPathToNode }, { type }) => { 'setup client side sketch segments': ({
context: { sketchPathToNode },
event: { type },
}) => {
if (Object.keys(sceneEntitiesManager.activeSegments).length > 0) { if (Object.keys(sceneEntitiesManager.activeSegments).length > 0) {
sceneEntitiesManager sceneEntitiesManager
.tearDownSketch({ removeAxis: false }) .tearDownSketch({ removeAxis: false })
@ -779,13 +796,15 @@ export const modelingMachine = createMachine(
} }
}, },
'remove sketch grid': () => sceneEntitiesManager.removeSketchGrid(), 'remove sketch grid': () => sceneEntitiesManager.removeSketchGrid(),
'set up draft line': ({ sketchPathToNode }) => { 'set up draft line': ({ context: { sketchPathToNode } }) => {
sceneEntitiesManager.setUpDraftLine(sketchPathToNode || []) sceneEntitiesManager.setUpDraftLine(sketchPathToNode || [])
}, },
'set up draft arc': ({ sketchPathToNode }) => { 'set up draft arc': ({ context: { sketchPathToNode } }) => {
sceneEntitiesManager.setUpDraftArc(sketchPathToNode || []) sceneEntitiesManager.setUpDraftArc(sketchPathToNode || [])
}, },
'set up draft line without teardown': ({ sketchPathToNode }) => 'set up draft line without teardown': ({
context: { sketchPathToNode },
}) =>
sceneEntitiesManager.setupSketch({ sceneEntitiesManager.setupSketch({
sketchPathToNode: sketchPathToNode || [], sketchPathToNode: sketchPathToNode || [],
draftSegment: 'line', draftSegment: 'line',
@ -795,7 +814,9 @@ export const modelingMachine = createMachine(
sceneEntitiesManager.setupDefaultPlaneHover() sceneEntitiesManager.setupDefaultPlaneHover()
kclManager.showPlanes() kclManager.showPlanes()
}, },
'setup noPoints onClick listener': ({ sketchPathToNode }) => { 'setup noPoints onClick listener': ({
context: { sketchPathToNode },
}) => {
sceneEntitiesManager.createIntersectionPlane() sceneEntitiesManager.createIntersectionPlane()
const sketchGroup = sketchGroupFromPathToNode({ const sketchGroup = sketchGroupFromPathToNode({
pathToNode: sketchPathToNode || [], pathToNode: sketchPathToNode || [],
@ -824,7 +845,7 @@ export const modelingMachine = createMachine(
}, },
}) })
}, },
'add axis n grid': ({ sketchPathToNode }) => 'add axis n grid': ({ context: { sketchPathToNode } }) =>
sceneEntitiesManager.createSketchAxis(sketchPathToNode || []), sceneEntitiesManager.createSketchAxis(sketchPathToNode || []),
'reset client scene mouse handlers': () => { 'reset client scene mouse handlers': () => {
// when not in sketch mode we don't need any mouse listeners // when not in sketch mode we don't need any mouse listeners

View File

@ -27,7 +27,6 @@ export const settingsMachine = createMachine(
{ {
/** @xstate-layout N4IgpgJg5mDOIC5QGUwBc0EsB2VYDpMIAbMAYlTQAIAVACzAFswBtABgF1FQAHAe1iYsfbNxAAPRAA42+AEwB2KQFYAzGznKAnADZli1QBoQAT2kBGKfm37lOned3nzqgL6vjlLLgJFSFdCoAETAAMwBDAFdiagAFACc+ACswAGNqADlw5nYuJBB+QWFRfMkEABY5fDYa2rra83LjMwQdLWV8BXLyuxlVLU1Ld090bzxCEnJKYLComODMeLS0PniTXLFCoUwRMTK7fC1zNql7NgUjtnKjU0RlBSqpLVUVPVUda60tYZAvHHG-FNAgBVbBCKjIEywNBMDb5LbFPaILqdfRSORsS4qcxXZqIHqyK6qY4XOxsGTKco-P4+Cb+aYAIXCsDAVFBQjhvAE212pWkskUKnUml0+gUNxaqkU+EccnKF1UCnucnMcjcHl+o3+vkmZBofCgUFIMwARpEoFRYuFsGBiJyCtzEXzWrJlGxlKdVFKvfY1XiEBjyvhVOVzBdzu13pYFNStbTAQFqAB5bAmvjheIQf4QtDhNCRWD2hE7EqgfayHTEh7lHQNSxSf1Scz4cpHHFyFVujTKczuDXYPgQOBiGl4TaOktIhAAWg6X3nC4Xp39050sYw2rpYHHRUnztVhPJqmUlIGbEriv9WhrLZ6uibHcqUr7riAA */ /** @xstate-layout N4IgpgJg5mDOIC5QGUwBc0EsB2VYDpMIAbMAYlTQAIAVACzAFswBtABgF1FQAHAe1iYsfbNxAAPRAA42+AEwB2KQFYAzGznKAnADZli1QBoQAT2kBGKfm37lOned3nzqgL6vjlLLgJFSFdCoAETAAMwBDAFdiagAFACc+ACswAGNqADlw5nYuJBB+QWFRfMkEABY5fDYa2rra83LjMwQdLWV8BXLyuxlVLU1Ld090bzxCEnJKYLComODMeLS0PniTXLFCoUwRMTK7fC1zNql7NgUjtnKjU0RlBSqpLVUVPVUda60tYZAvHHG-FNAgBVbBCKjIEywNBMDb5LbFPaILqdfRSORsS4qcxXZqIHqyK6qY4XOxsGTKco-P4+Cb+aYAIXCsDAVFBQjhvAE212pWkskUKnUml0+gUNxaqkU+EccnKF1UCnucnMcjcHl+o3+vkmZBofCgUFIMwARpEoFRYuFsGBiJyCtzEXzWrJlGxlKdVFKvfY1XiEBjyvhVOVzBdzu13pYFNStbTAQFqAB5bAmvjheIQf4QtDhNCRWD2hE7EqgfayHTEh7lHQNSxSf1Scz4cpHHFyFVujTKczuDXYPgQOBiGl4TaOktIhAAWg6X3nC4Xp39050sYw2rpYHHRUnztVhPJqmUlIGbEriv9WhrLZ6uibHcqUr7riAA */
id: 'Settings', id: 'Settings',
predictableActionArguments: true,
context: { context: {
baseUnit: 'in' as BaseUnit, baseUnit: 'in' as BaseUnit,
cameraControls: 'KittyCAD' as CameraSystem, cameraControls: 'KittyCAD' as CameraSystem,
@ -47,7 +46,7 @@ export const settingsMachine = createMachine(
'Set Base Unit': { 'Set Base Unit': {
actions: [ actions: [
assign({ assign({
baseUnit: (_, event) => { baseUnit: ({ event }) => {
console.log('event', event) console.log('event', event)
return event.data.baseUnit return event.data.baseUnit
}, },
@ -56,92 +55,92 @@ export const settingsMachine = createMachine(
'toastSuccess', 'toastSuccess',
], ],
target: 'idle', target: 'idle',
internal: true, reenter: false,
}, },
'Set Camera Controls': { 'Set Camera Controls': {
actions: [ actions: [
assign({ assign({
cameraControls: (_, event) => event.data.cameraControls, cameraControls: ({ event }) => event.data.cameraControls,
}), }),
'persistSettings', 'persistSettings',
'toastSuccess', 'toastSuccess',
], ],
target: 'idle', target: 'idle',
internal: true, reenter: false,
}, },
'Set Default Directory': { 'Set Default Directory': {
actions: [ actions: [
assign({ assign({
defaultDirectory: (_, event) => event.data.defaultDirectory, defaultDirectory: ({ event }) => event.data.defaultDirectory,
}), }),
'persistSettings', 'persistSettings',
'toastSuccess', 'toastSuccess',
], ],
target: 'idle', target: 'idle',
internal: true, reenter: false,
}, },
'Set Default Project Name': { 'Set Default Project Name': {
actions: [ actions: [
assign({ assign({
defaultProjectName: (_, event) => defaultProjectName: ({ event }) =>
event.data.defaultProjectName.trim() || DEFAULT_PROJECT_NAME, event.data.defaultProjectName.trim() || DEFAULT_PROJECT_NAME,
}), }),
'persistSettings', 'persistSettings',
'toastSuccess', 'toastSuccess',
], ],
target: 'idle', target: 'idle',
internal: true, reenter: false,
}, },
'Set Onboarding Status': { 'Set Onboarding Status': {
actions: [ actions: [
assign({ assign({
onboardingStatus: (_, event) => event.data.onboardingStatus, onboardingStatus: ({ event }) => event.data.onboardingStatus,
}), }),
'persistSettings', 'persistSettings',
], ],
target: 'idle', target: 'idle',
internal: true, reenter: false,
}, },
'Set Text Wrapping': { 'Set Text Wrapping': {
actions: [ actions: [
assign({ assign({
textWrapping: (_, event) => event.data.textWrapping, textWrapping: ({ event }) => event.data.textWrapping,
}), }),
'persistSettings', 'persistSettings',
'toastSuccess', 'toastSuccess',
], ],
target: 'idle', target: 'idle',
internal: true, reenter: false,
}, },
'Set Theme': { 'Set Theme': {
actions: [ actions: [
assign({ assign({
theme: (_, event) => event.data.theme, theme: ({ event }) => event.data.theme,
}), }),
'persistSettings', 'persistSettings',
'toastSuccess', 'toastSuccess',
'setThemeClass', 'setThemeClass',
], ],
target: 'idle', target: 'idle',
internal: true, reenter: false,
}, },
'Set Unit System': { 'Set Unit System': {
actions: [ actions: [
assign({ assign({
unitSystem: (_, event) => event.data.unitSystem, unitSystem: ({ event }) => event.data.unitSystem,
baseUnit: (_, event) => baseUnit: ({ event }) =>
event.data.unitSystem === 'imperial' ? 'in' : 'mm', event.data.unitSystem === 'imperial' ? 'in' : 'mm',
}), }),
'persistSettings', 'persistSettings',
'toastSuccess', 'toastSuccess',
], ],
target: 'idle', target: 'idle',
internal: true, reenter: false,
}, },
'Toggle Debug Panel': { 'Toggle Debug Panel': {
actions: [ actions: [
assign({ assign({
showDebugPanel: (context) => { showDebugPanel: ({ context }) => {
return !context.showDebugPanel return !context.showDebugPanel
}, },
}), }),
@ -149,13 +148,13 @@ export const settingsMachine = createMachine(
'toastSuccess', 'toastSuccess',
], ],
target: 'idle', target: 'idle',
internal: true, reenter: false,
}, },
}, },
}, },
}, },
tsTypes: {} as import('./settingsMachine.typegen').Typegen0, tsTypes: {} as import('./settingsMachine.typegen').Typegen0,
schema: { types: {
events: {} as events: {} as
| { type: 'Set Base Unit'; data: { baseUnit: BaseUnit } } | { type: 'Set Base Unit'; data: { baseUnit: BaseUnit } }
| { | {
@ -186,7 +185,7 @@ export const settingsMachine = createMachine(
console.error(e) console.error(e)
} }
}, },
setThemeClass: (context, event) => { setThemeClass: ({ context, event }) => {
const currentTheme = const currentTheme =
event.type === 'Set Theme' ? event.data.theme : context.theme event.type === 'Set Theme' ? event.data.theme : context.theme
setThemeClass( setThemeClass(

View File

@ -1,5 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"strictNullChecks": true,
"baseUrl": "src", "baseUrl": "src",
"paths": { "paths": {
"/*": ["src/*"] "/*": ["src/*"]

View File

@ -2887,10 +2887,10 @@
"@babel/types" "^7.21.4" "@babel/types" "^7.21.4"
recast "^0.23.1" recast "^0.23.1"
"@xstate/react@^3.2.2": "@xstate/react@^4.1.0":
version "3.2.2" version "4.1.0"
resolved "https://registry.yarnpkg.com/@xstate/react/-/react-3.2.2.tgz#ddf0f9d75e2c19375b1e1b7335e72cb99762aed8" resolved "https://registry.yarnpkg.com/@xstate/react/-/react-4.1.0.tgz#369378951e1f7f9326700f65ed02847598aad704"
integrity sha512-feghXWLedyq8JeL13yda3XnHPZKwYDN5HPBLykpLeuNpr9178tQd2/3d0NrH6gSd0sG5mLuLeuD+ck830fgzLQ== integrity sha512-Fh89luCwuMXIVXIua67d8pNuVgdGpqke2jHfIIL+ZjkfNh6YFtPDSwNSZZDhdNUsOW1zZYSbtUzbC8MIUyTSHQ==
dependencies: dependencies:
use-isomorphic-layout-effect "^1.1.2" use-isomorphic-layout-effect "^1.1.2"
use-sync-external-store "^1.0.0" use-sync-external-store "^1.0.0"
@ -8992,11 +8992,16 @@ ws@^8.8.0:
resolved "https://registry.yarnpkg.com/xstate/-/xstate-5.0.0-beta.54.tgz#d80f1a9e43ad883a65fc9b399161bd39633bd9bf" resolved "https://registry.yarnpkg.com/xstate/-/xstate-5.0.0-beta.54.tgz#d80f1a9e43ad883a65fc9b399161bd39633bd9bf"
integrity sha512-BTnCPBQ2iTKe4uCnHEe1hNx6VTbXU+5mQGybSQHOjTLiBi4Ryi+tL9T6N1tmqagvM8rfl4XRfvndogfWCWcdpw== integrity sha512-BTnCPBQ2iTKe4uCnHEe1hNx6VTbXU+5mQGybSQHOjTLiBi4Ryi+tL9T6N1tmqagvM8rfl4XRfvndogfWCWcdpw==
xstate@^4.33.4, xstate@^4.38.2: xstate@^4.33.4:
version "4.38.3" version "4.38.3"
resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.38.3.tgz#4e15e7ad3aa0ca1eea2010548a5379966d8f1075" resolved "https://registry.yarnpkg.com/xstate/-/xstate-4.38.3.tgz#4e15e7ad3aa0ca1eea2010548a5379966d8f1075"
integrity sha512-SH7nAaaPQx57dx6qvfcIgqKRXIh4L0A1iYEqim4s1u7c9VoCgzZc+63FY90AKU4ZzOC2cfJzTnpO4zK7fCUzzw== integrity sha512-SH7nAaaPQx57dx6qvfcIgqKRXIh4L0A1iYEqim4s1u7c9VoCgzZc+63FY90AKU4ZzOC2cfJzTnpO4zK7fCUzzw==
xstate@^5.7.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/xstate/-/xstate-5.7.1.tgz#c9d6af13c01e223437b53648be59b55f85f43288"
integrity sha512-x1fa1X/K2bCdXrN6Hrll30Q00iprXaaPqB0U3N4nUgjngTNxQbnBvAQ4WSH6ctdU3jbH32+S3GDYctM5K7t8Vw==
y18n@^5.0.5: y18n@^5.0.5:
version "5.0.8" version "5.0.8"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"