This commit upgrades TypeScript to the latest version 5.3 and introduces `verbatimModuleSyntax` in line with the official Vue guide recommendatinos (vuejs/docs#2592). By enforcing `import type` for type-only imports, this commit improves code clarity and supports tooling optimization, ensuring imports are only bundled when necessary for runtime. Changes: - Bump TypeScript to 5.3.3 across the project. - Adjust import statements to utilize `import type` where applicable, promoting cleaner and more efficient code.
80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
import type { SelectedScript } from '@/application/Context/State/Selection/Script/SelectedScript';
|
|
import type { ReadonlyScriptSelection, ScriptSelection } from '@/application/Context/State/Selection/Script/ScriptSelection';
|
|
import type { ScriptSelectionChange } from '@/application/Context/State/Selection/Script/ScriptSelectionChange';
|
|
import { RevertStatusType } from './RevertStatusType';
|
|
|
|
export function setCurrentRevertStatus(
|
|
desiredRevertStatus: boolean,
|
|
selection: ScriptSelection,
|
|
) {
|
|
const scriptRevertStatusChanges = getScriptRevertStatusChanges(
|
|
selection.selectedScripts,
|
|
desiredRevertStatus,
|
|
);
|
|
if (scriptRevertStatusChanges.length === 0) {
|
|
return;
|
|
}
|
|
selection.processChanges({ changes: scriptRevertStatusChanges });
|
|
}
|
|
|
|
export function getCurrentRevertStatus(
|
|
selection: ReadonlyScriptSelection,
|
|
): RevertStatusType {
|
|
const allScriptRevertStatuses = filterReversibleScripts(selection.selectedScripts)
|
|
.map((selectedScript) => selectedScript.revert);
|
|
if (!allScriptRevertStatuses.length) {
|
|
return RevertStatusType.NoReversibleScripts;
|
|
}
|
|
if (allScriptRevertStatuses.every((revertStatus) => revertStatus)) {
|
|
return RevertStatusType.AllScriptsReverted;
|
|
}
|
|
if (allScriptRevertStatuses.every((revertStatus) => !revertStatus)) {
|
|
return RevertStatusType.NoScriptsReverted;
|
|
}
|
|
return RevertStatusType.SomeScriptsReverted;
|
|
}
|
|
|
|
function getScriptRevertStatusChanges(
|
|
selectedScripts: readonly SelectedScript[],
|
|
desiredRevertStatus: boolean,
|
|
): ScriptSelectionChange[] {
|
|
const reversibleSelectedScripts = filterReversibleScripts(selectedScripts);
|
|
const selectedScriptsRequiringChange = filterScriptsRequiringRevertStatusChange(
|
|
reversibleSelectedScripts,
|
|
desiredRevertStatus,
|
|
);
|
|
const revertStatusChanges = mapToScriptSelectionChanges(
|
|
selectedScriptsRequiringChange,
|
|
desiredRevertStatus,
|
|
);
|
|
return revertStatusChanges;
|
|
}
|
|
|
|
function filterReversibleScripts(selectedScripts: readonly SelectedScript[]) {
|
|
return selectedScripts.filter(
|
|
(selectedScript) => selectedScript.script.canRevert(),
|
|
);
|
|
}
|
|
|
|
function filterScriptsRequiringRevertStatusChange(
|
|
selectedScripts: readonly SelectedScript[],
|
|
desiredRevertStatus: boolean,
|
|
) {
|
|
return selectedScripts.filter(
|
|
(selectedScript) => selectedScript.revert !== desiredRevertStatus,
|
|
);
|
|
}
|
|
|
|
function mapToScriptSelectionChanges(
|
|
scriptsNeedingChange: readonly SelectedScript[],
|
|
newRevertStatus: boolean,
|
|
): ScriptSelectionChange[] {
|
|
return scriptsNeedingChange.map((script): ScriptSelectionChange => ({
|
|
scriptId: script.id,
|
|
newStatus: {
|
|
isSelected: true,
|
|
isReverted: newRevertStatus,
|
|
},
|
|
}));
|
|
}
|