|
1 | 1 | import { mapValues } from "lodash";
|
2 |
| -import { SpokenFormMap, SpokenFormMapKeyTypes } from "./SpokenFormMap"; |
| 2 | +import { |
| 3 | + SpokenFormMap, |
| 4 | + SpokenFormMapEntry, |
| 5 | + SpokenFormMapKeyTypes, |
| 6 | +} from "./SpokenFormMap"; |
3 | 7 |
|
4 |
| -type DefaultSpokenFormMap = { |
| 8 | +type DefaultSpokenFormMapDefinition = { |
5 | 9 | readonly [K in keyof SpokenFormMapKeyTypes]: Readonly<
|
6 |
| - Record<SpokenFormMapKeyTypes[K], string | null> |
| 10 | + Record<SpokenFormMapKeyTypes[K], string | DefaultSpokenFormMapEntry> |
7 | 11 | >;
|
8 | 12 | };
|
9 | 13 |
|
10 |
| -const defaultSpokenFormMapCore: DefaultSpokenFormMap = { |
| 14 | +const defaultSpokenFormMapCore: DefaultSpokenFormMapDefinition = { |
11 | 15 | pairedDelimiter: {
|
12 | 16 | curlyBrackets: "curly",
|
13 | 17 | angleBrackets: "diamond",
|
@@ -45,15 +49,14 @@ const defaultSpokenFormMapCore: DefaultSpokenFormMap = {
|
45 | 49 | name: "name",
|
46 | 50 | regularExpression: "regex",
|
47 | 51 | section: "section",
|
48 |
| - sectionLevelOne: "one section", |
49 |
| - sectionLevelTwo: "two section", |
50 |
| - sectionLevelThree: "three section", |
51 |
| - sectionLevelFour: "four section", |
52 |
| - sectionLevelFive: "five section", |
53 |
| - sectionLevelSix: "six section", |
| 52 | + sectionLevelOne: disabledByDefault("one section"), |
| 53 | + sectionLevelTwo: disabledByDefault("two section"), |
| 54 | + sectionLevelThree: disabledByDefault("three section"), |
| 55 | + sectionLevelFour: disabledByDefault("four section"), |
| 56 | + sectionLevelFive: disabledByDefault("five section"), |
| 57 | + sectionLevelSix: disabledByDefault("six section"), |
54 | 58 | selector: "selector",
|
55 | 59 | statement: "state",
|
56 |
| - string: "string", |
57 | 60 | branch: "branch",
|
58 | 61 | type: "type",
|
59 | 62 | value: "value",
|
@@ -88,7 +91,8 @@ const defaultSpokenFormMapCore: DefaultSpokenFormMap = {
|
88 | 91 | url: "link",
|
89 | 92 | notebookCell: "cell",
|
90 | 93 |
|
91 |
| - switchStatementSubject: null, |
| 94 | + string: secret("parse tree string"), |
| 95 | + switchStatementSubject: secret("subject"), |
92 | 96 | },
|
93 | 97 |
|
94 | 98 | surroundingPairForceDirection: {
|
@@ -124,10 +128,67 @@ const defaultSpokenFormMapCore: DefaultSpokenFormMap = {
|
124 | 128 | customRegex: {},
|
125 | 129 | };
|
126 | 130 |
|
127 |
| -// TODO: Don't cast here; need to make our own mapValues with stronger typing |
| 131 | +function disabledByDefault( |
| 132 | + ...spokenForms: string[] |
| 133 | +): DefaultSpokenFormMapEntry { |
| 134 | + return { |
| 135 | + defaultSpokenForms: spokenForms, |
| 136 | + isDisabledByDefault: true, |
| 137 | + isSecret: false, |
| 138 | + }; |
| 139 | +} |
| 140 | + |
| 141 | +function secret(...spokenForms: string[]): DefaultSpokenFormMapEntry { |
| 142 | + return { |
| 143 | + defaultSpokenForms: spokenForms, |
| 144 | + isDisabledByDefault: true, |
| 145 | + isSecret: true, |
| 146 | + }; |
| 147 | +} |
| 148 | + |
| 149 | +interface DefaultSpokenFormMapEntry { |
| 150 | + defaultSpokenForms: string[]; |
| 151 | + isDisabledByDefault: boolean; |
| 152 | + isSecret: boolean; |
| 153 | +} |
| 154 | + |
| 155 | +export type DefaultSpokenFormMap = { |
| 156 | + readonly [K in keyof SpokenFormMapKeyTypes]: Readonly< |
| 157 | + Record<SpokenFormMapKeyTypes[K], DefaultSpokenFormMapEntry> |
| 158 | + >; |
| 159 | +}; |
| 160 | + |
| 161 | +// FIXME: Don't cast here; need to make our own mapValues with stronger typing |
128 | 162 | // using tricks from our object.d.ts
|
129 |
| -export const defaultSpokenFormMap = mapValues( |
| 163 | +export const defaultSpokenFormInfo = mapValues( |
130 | 164 | defaultSpokenFormMapCore,
|
131 | 165 | (entry) =>
|
132 |
| - mapValues(entry, (subEntry) => (subEntry == null ? [] : [subEntry])), |
| 166 | + mapValues(entry, (subEntry) => |
| 167 | + typeof subEntry === "string" |
| 168 | + ? { |
| 169 | + defaultSpokenForms: [subEntry], |
| 170 | + isDisabledByDefault: false, |
| 171 | + isSecret: false, |
| 172 | + } |
| 173 | + : subEntry, |
| 174 | + ), |
| 175 | +) as DefaultSpokenFormMap; |
| 176 | + |
| 177 | +// FIXME: Don't cast here; need to make our own mapValues with stronger typing |
| 178 | +// using tricks from our object.d.ts |
| 179 | +export const defaultSpokenFormMap = mapValues(defaultSpokenFormInfo, (entry) => |
| 180 | + mapValues( |
| 181 | + entry, |
| 182 | + ({ |
| 183 | + defaultSpokenForms, |
| 184 | + isDisabledByDefault, |
| 185 | + isSecret, |
| 186 | + }): SpokenFormMapEntry => ({ |
| 187 | + spokenForms: isDisabledByDefault ? [] : defaultSpokenForms, |
| 188 | + isCustom: false, |
| 189 | + defaultSpokenForms, |
| 190 | + requiresTalonUpdate: false, |
| 191 | + isSecret, |
| 192 | + }), |
| 193 | + ), |
133 | 194 | ) as SpokenFormMap;
|
0 commit comments