Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"alias": "y.chibicode.com",
"github": {
"silent": true
},
"engines": {
"node": "10.x"
}
}
3 changes: 2 additions & 1 deletion scripts/copyUsedEmojis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ const allUsedEmojis = uniq<string>([
'🔠',
'🐍',
'💡',
'🎁'
'🎁',
'🗓'
])

// Copied from Twemoji
Expand Down
132 changes: 70 additions & 62 deletions scripts/lib/buildExpressionContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as lessonExpressions from 'scripts/lib/lessonExpressions'

const buildExpressionContainers = ({
lessonExpressionsKey,
predefinedExpressionsKeys,
initializeInstructions,
showAllShowSteps,
skipAlphaConvert,
Expand All @@ -18,99 +19,106 @@ const buildExpressionContainers = ({
lastAllowedExpressionStateAfterIterations,
hidePlayButton
}: ExpressionRunnerConfig): readonly ExpressionContainer[] => {
let currentExpressionContainer: SteppedExpressionContainer =
lessonExpressions[lessonExpressionsKey]
let results: ExpressionContainer[] = []
const stepOptions = { showAllShowSteps, skipAlphaConvert }
if (lessonExpressionsKey) {
let currentExpressionContainer: SteppedExpressionContainer =
lessonExpressions[lessonExpressionsKey]
let results: ExpressionContainer[] = []
const stepOptions = { showAllShowSteps, skipAlphaConvert }

initializeInstructions.forEach(initializeInstruction => {
if (
initializeInstruction.type ===
'stepForwardUntilPreviouslyChangedExpressionState'
) {
while (
currentExpressionContainer.previouslyChangedExpressionState !==
initializeInstruction.state &&
!isContainerWithState(currentExpressionContainer, 'done')
initializeInstructions.forEach(initializeInstruction => {
if (
initializeInstruction.type ===
'stepForwardUntilPreviouslyChangedExpressionState'
) {
currentExpressionContainer = stepExpressionContainer(
currentExpressionContainer,
stepOptions
)
}
} else if (initializeInstruction.type === 'nextIteration') {
if (!isContainerWithState(currentExpressionContainer, 'done')) {
currentExpressionContainer = stepExpressionContainer(
currentExpressionContainer,
stepOptions
)
while (
currentExpressionContainer.previouslyChangedExpressionState !==
'default' &&
initializeInstruction.state &&
!isContainerWithState(currentExpressionContainer, 'done')
) {
currentExpressionContainer = stepExpressionContainer(
currentExpressionContainer,
stepOptions
)
}
} else if (initializeInstruction.type === 'nextIteration') {
if (!isContainerWithState(currentExpressionContainer, 'done')) {
currentExpressionContainer = stepExpressionContainer(
currentExpressionContainer,
stepOptions
)
while (
currentExpressionContainer.previouslyChangedExpressionState !==
'default' &&
!isContainerWithState(currentExpressionContainer, 'done')
) {
currentExpressionContainer = stepExpressionContainer(
currentExpressionContainer,
stepOptions
)
}
}
} else {
while (!isContainerWithState(currentExpressionContainer, 'done')) {
currentExpressionContainer = stepExpressionContainer(
currentExpressionContainer,
stepOptions
)
}
}
} else {
})

results.push(currentExpressionContainer)

if (hideControls) {
return results
}

if (skipToTheEnd) {
while (!isContainerWithState(currentExpressionContainer, 'done')) {
currentExpressionContainer = stepExpressionContainer(
currentExpressionContainer,
stepOptions
)
}
results.push(currentExpressionContainer)
return results
}
})

results.push(currentExpressionContainer)

if (hideControls) {
return results
}

if (skipToTheEnd) {
let becameDefaultCount = 0
while (!isContainerWithState(currentExpressionContainer, 'done')) {
currentExpressionContainer = stepExpressionContainer(
currentExpressionContainer,
stepOptions
)
}
results.push(currentExpressionContainer)
return results
}
results.push(currentExpressionContainer)

let becameDefaultCount = 0
while (!isContainerWithState(currentExpressionContainer, 'done')) {
currentExpressionContainer = stepExpressionContainer(
currentExpressionContainer,
stepOptions
)
results.push(currentExpressionContainer)
if (hidePlayButton) {
break
}

if (hidePlayButton) {
break
}
if (
lastAllowedExpressionState &&
lastAllowedExpressionState ===
currentExpressionContainer.previouslyChangedExpressionState &&
(lastAllowedExpressionStateAfterIterations || 0) <= becameDefaultCount
) {
break
}

if (
lastAllowedExpressionState &&
lastAllowedExpressionState ===
currentExpressionContainer.previouslyChangedExpressionState &&
(lastAllowedExpressionStateAfterIterations || 0) <= becameDefaultCount
) {
break
if (
currentExpressionContainer.previouslyChangedExpressionState ===
'default'
) {
becameDefaultCount += 1
}
}

if (
currentExpressionContainer.previouslyChangedExpressionState === 'default'
) {
becameDefaultCount += 1
}
return results
} else if (predefinedExpressionsKeys) {
return predefinedExpressionsKeys.map(key => lessonExpressions[key])
} else {
throw new Error()
}

return results
}

export default buildExpressionContainers
37 changes: 34 additions & 3 deletions scripts/lib/buildExpressionRunnerConfigFromShorthand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {
expressionRunnerSimpleConfigDefault,
expressionRunnerPlayButtonOnlyConfigDefault,
expressionRunnerSingleStepConfigDefault,
expressionRunnerPredefinedConfigDefault,
isExpressionRunnerSimpleConfig,
isExpressionRunnerPlayButtonOnlyConfig
isExpressionRunnerPlayButtonOnlyConfig,
isExpressionRunnerSingleStepConfig
} from 'scripts/lib/expressionRunnerShorthandConfig'
import { ExpressionContainer } from 'src/types/ExpressionContainerTypes'
import { allMaxWidths } from 'src/lib/theme/maxWidths'
Expand All @@ -17,7 +19,8 @@ import { HProps } from 'src/types/HTypes'
import * as lessonExpressions from 'scripts/lib/lessonExpressions'

export interface ExpressionRunnerConfig {
lessonExpressionsKey: keyof typeof lessonExpressions
lessonExpressionsKey?: keyof typeof lessonExpressions
predefinedExpressionsKeys?: readonly (keyof typeof lessonExpressions)[]
hidePriorities: ExpressionRunnerContextProps['hidePriorities']
hideBottomRightBadges: ExpressionRunnerContextProps['hideBottomRightBadges']
hideControls: boolean
Expand Down Expand Up @@ -233,7 +236,7 @@ const buildExpressionRunnerConfigFromShorthand = (
}),
superFastForward
}
} else {
} else if (isExpressionRunnerSingleStepConfig(config)) {
const {
lessonExpressionsKey,
initialState,
Expand Down Expand Up @@ -268,6 +271,34 @@ const buildExpressionRunnerConfigFromShorthand = (
initialState
})
}
} else {
const {
predefinedExpressionsKeys,
hideFuncUnboundBadgeOnExplanation,
showPriorities,
explanationsVisibility,
showAllShowSteps,
variableSize,
containerSize,
nextIterations,
skipToTheEnd
} = mergeWithDefault<
typeof config,
typeof expressionRunnerPredefinedConfigDefault
>(config, expressionRunnerPredefinedConfigDefault)

runnerProps = {
predefinedExpressionsKeys,
variableSize,
containerSize,
hidePriorities: !showPriorities,
hideFuncUnboundBadgeOnExplanation,
hidePlayButton: false,
explanationsVisibility,
lastAllowedExpressionStateAfterIterations: nextIterations,
showAllShowSteps,
skipToTheEnd
}
}

return mergeWithDefault<typeof runnerProps, typeof expressionRunnerDefaults>(
Expand Down
29 changes: 29 additions & 0 deletions scripts/lib/expressionRunnerShorthandConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,36 @@ interface ExpressionRunnerSingleStepConfig {
showAllShowSteps?: ExpressionRunnerProps['showAllShowSteps']
}

export function isExpressionRunnerPredefinedConfig(
c: ExpressionRunnerShorthandConfig
): c is ExpressionRunnerPredefinedConfig {
return c.runner === 'predefined'
}

export const expressionRunnerPredefinedConfigDefault = {
hideFuncUnboundBadgeOnExplanation: false,
showPriorities: false,
explanationsVisibility: 'hiddenInitialPausedOnly',
variableSize: 'lg',
skipToTheEnd: true
}

interface ExpressionRunnerPredefinedConfig {
runner: 'predefined'
predefinedExpressionsKeys: readonly (keyof typeof lessonExpressions)[]
hideFuncUnboundBadgeOnExplanation?: boolean
showPriorities?: boolean
nextIteration?: boolean
nextIterations?: number
variableSize?: ExpressionRunnerProps['variableSize']
containerSize?: ExpressionRunnerProps['containerSize']
explanationsVisibility?: ExpressionRunnerProps['explanationsVisibility']
showAllShowSteps?: ExpressionRunnerProps['showAllShowSteps']
skipToTheEnd?: boolean
}

export type ExpressionRunnerShorthandConfig =
| ExpressionRunnerSimpleConfig
| ExpressionRunnerPlayButtonOnlyConfig
| ExpressionRunnerSingleStepConfig
| ExpressionRunnerPredefinedConfig
Loading