fix: Narrow the type of Action.name while still allowing custom names
This commit is contained in:
@@ -28,7 +28,7 @@ let parentTypeMap: readonly {
|
||||
}[] = [];
|
||||
let subtypeActionMap: readonly {
|
||||
subtype: Subtype;
|
||||
actions: readonly SubtypeActionName[];
|
||||
actions: readonly ActionName[];
|
||||
}[] = [];
|
||||
let disabledActionMap: readonly {
|
||||
subtype: Subtype;
|
||||
@@ -91,7 +91,7 @@ const isDisabledActionName = (s: any): s is DisabledActionName =>
|
||||
// by `subtype` (if `isAdded` is false)?
|
||||
const isForSubtype = (
|
||||
subtype: ExcalidrawElement["subtype"],
|
||||
actionName: ActionName | SubtypeActionName,
|
||||
actionName: ActionName,
|
||||
isAdded: boolean,
|
||||
) => {
|
||||
const actions = isAdded ? subtypeActionMap : disabledActionMap;
|
||||
@@ -371,7 +371,12 @@ export const prepareSubtype = (
|
||||
if (record.actionNames) {
|
||||
subtypeActionMap = [
|
||||
...subtypeActionMap,
|
||||
{ subtype, actions: record.actionNames },
|
||||
{
|
||||
subtype,
|
||||
actions: record.actionNames.map(
|
||||
(actionName) => `custom.${actionName}` as ActionName,
|
||||
),
|
||||
},
|
||||
];
|
||||
}
|
||||
if (record.disabledNames) {
|
||||
@@ -383,7 +388,12 @@ export const prepareSubtype = (
|
||||
if (record.alwaysEnabledNames) {
|
||||
alwaysEnabledMap = [
|
||||
...alwaysEnabledMap,
|
||||
{ subtype, actions: record.alwaysEnabledNames },
|
||||
{
|
||||
subtype,
|
||||
actions: record.alwaysEnabledNames.map(
|
||||
(actionName) => `custom.${actionName}` as ActionName,
|
||||
),
|
||||
},
|
||||
];
|
||||
}
|
||||
if (record.shortcutMap) {
|
||||
|
||||
@@ -1395,7 +1395,7 @@ const enableActionChangeMathProps = (
|
||||
const createMathActions = () => {
|
||||
const mathActions: Action[] = [];
|
||||
const actionUseTexTrue: Action = {
|
||||
name: "useTexTrue",
|
||||
name: "custom.useTexTrue",
|
||||
perform: (elements, appState) => {
|
||||
const mathOnly = getMathProps.getMathOnly(appState);
|
||||
const customData = appState.customData ?? {};
|
||||
@@ -1414,7 +1414,7 @@ const createMathActions = () => {
|
||||
trackEvent: false,
|
||||
};
|
||||
const actionUseTexFalse: Action = {
|
||||
name: "useTexFalse",
|
||||
name: "custom.useTexFalse",
|
||||
perform: (elements, appState) => {
|
||||
const mathOnly = getMathProps.getMathOnly(appState);
|
||||
const customData = appState.customData ?? {};
|
||||
@@ -1433,7 +1433,7 @@ const createMathActions = () => {
|
||||
trackEvent: false,
|
||||
};
|
||||
const actionResetUseTex: Action = {
|
||||
name: "resetUseTex",
|
||||
name: "custom.resetUseTex",
|
||||
perform: (elements, appState) => {
|
||||
const useTex = getMathProps.getUseTex(appState);
|
||||
const modElements = changeProperty(
|
||||
@@ -1481,7 +1481,7 @@ const createMathActions = () => {
|
||||
trackEvent: false,
|
||||
};
|
||||
const actionChangeMathOnly: Action = {
|
||||
name: "changeMathOnly",
|
||||
name: "custom.changeMathOnly",
|
||||
perform: (elements, appState, mathOnly: boolean | null) => {
|
||||
if (mathOnly === null) {
|
||||
mathOnly = getFormValue(
|
||||
|
||||
Reference in New Issue
Block a user