Skip to content

Commit 55dbef1

Browse files
committed
fixing 3 bugs in grid3
1 parent ba1d5d4 commit 55dbef1

3 files changed

Lines changed: 72 additions & 2 deletions

File tree

src/core/treeStructure.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ export class AACPage {
410410
descriptionHtml?: string;
411411
images?: any[];
412412
sounds?: any[];
413+
// Page-level WordList items (extracted from Grid3 <WordList>; surfaced
414+
// regardless of whether AutoContent WordList cells exist in the grid).
415+
wordListItems?: import('../types/aac').AACWordListItem[];
413416
// Metrics support: Track semantic/clone IDs used on this page
414417
semantic_ids?: string[];
415418
clone_ids?: string[];

src/processors/gridset/commands.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,57 @@ export interface ExtractedParameters {
963963
[key: string]: string | number | boolean;
964964
}
965965

966+
function textOfStructured(val: any): string | undefined {
967+
if (!val || typeof val !== 'object') return undefined;
968+
969+
const parts: string[] = [];
970+
const processS = (s: any): void => {
971+
if (!s) return;
972+
if (s.r !== undefined) {
973+
const rElements = Array.isArray(s.r) ? s.r : [s.r];
974+
for (const r of rElements) {
975+
if (typeof r === 'number') {
976+
if (r !== 0) parts.push(String(r));
977+
continue;
978+
}
979+
if (typeof r === 'object' && r !== null) {
980+
if ('#text' in r) parts.push(String(r['#text']));
981+
else if ('#cdata' in r) parts.push(String(r['#cdata']));
982+
else parts.push(String(r));
983+
} else {
984+
parts.push(String(r));
985+
}
986+
}
987+
}
988+
};
989+
990+
if (val.p) {
991+
const sElements = Array.isArray(val.p.s) ? val.p.s : val.p.s ? [val.p.s] : [];
992+
sElements.forEach(processS);
993+
} else if (val.s) {
994+
const sElements = Array.isArray(val.s) ? val.s : [val.s];
995+
sElements.forEach(processS);
996+
} else if (val.r !== undefined) {
997+
processS(val);
998+
}
999+
1000+
return parts.length > 0 ? parts.join('').trim() : undefined;
1001+
}
1002+
1003+
function extractParamValue(param: any): string | number | boolean | undefined {
1004+
if (typeof param === 'string') return param;
1005+
1006+
if (param.p || param.s || (param.r !== undefined && typeof param.r !== 'string')) {
1007+
const structured = textOfStructured(param);
1008+
if (structured !== undefined) return structured;
1009+
}
1010+
1011+
const simple = param['#text'] ?? param.text ?? param.value;
1012+
if (simple !== undefined) return simple as string | number | boolean;
1013+
1014+
return textOfStructured(param);
1015+
}
1016+
9661017
export function extractCommandParameters(command: any): ExtractedParameters {
9671018
const parameters: ExtractedParameters = {};
9681019
const params = command.Parameter || command.parameter;
@@ -973,7 +1024,7 @@ export function extractCommandParameters(command: any): ExtractedParameters {
9731024

9741025
for (const param of paramArray) {
9751026
const key = param['@_Key'] || param.Key || param.key;
976-
let value = param['#text'] ?? param.text ?? param.value;
1027+
let value = extractParamValue(param);
9771028

9781029
if (key && value !== undefined) {
9791030
// Try to convert to number if it looks numeric

src/processors/gridsetProcessor.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,14 @@ class GridsetProcessor extends BaseProcessor {
794794
}
795795
}
796796

797+
if (pageWordListItems.length > 0) {
798+
page.wordListItems = pageWordListItems.map((item) => ({
799+
text: item.text,
800+
image: item.image,
801+
partOfSpeech: item.partOfSpeech,
802+
}));
803+
}
804+
797805
// Track WordList AutoContent cells and their positions for "more" button placement
798806
const wordListAutoContentCells: Array<{
799807
cell: any;
@@ -1190,12 +1198,20 @@ class GridsetProcessor extends BaseProcessor {
11901198
const getParam = (key: string): string | undefined => {
11911199
const param = getRawParam(key);
11921200
if (param === undefined) return undefined;
1201+
if (typeof param === 'string') return param;
1202+
if (
1203+
param.p ||
1204+
param.s ||
1205+
(param.r !== undefined && typeof param.r !== 'string')
1206+
) {
1207+
const structuredValue = this.textOf(param);
1208+
if (structuredValue !== undefined) return structuredValue;
1209+
}
11931210
const simpleValue = param['#text'] ?? param.text ?? param.value;
11941211
if (typeof simpleValue === 'string') return simpleValue;
11951212
if (typeof simpleValue === 'number') return String(simpleValue);
11961213
const structuredValue = this.textOf(param);
11971214
if (structuredValue !== undefined) return structuredValue;
1198-
if (typeof param === 'string') return param;
11991215
return undefined;
12001216
};
12011217

0 commit comments

Comments
 (0)