@@ -2592,7 +2592,34 @@ class GridsetProcessor extends BaseProcessor {
25922592 // Check if there's a modified button for this position
25932593 const modifiedButton = buttonsByPosition . get ( key ) ;
25942594 if ( modifiedButton ) {
2595- // Update the caption
2595+ // Check if this is an AutoContent/WordList cell
2596+ const isWordListCell =
2597+ ( cell . Content . ContentType === 'AutoContent' || cell . Content . ContentType === 'AutoContent' ) &&
2598+ ( cell . Content . ContentSubType === 'WordList' || cell . Content . ContentSubType === 'WordList' ) ;
2599+
2600+ if ( isWordListCell ) {
2601+ // For WordList cells, we need to add the word to the page's WordList
2602+ // instead of modifying the cell directly. The cell will automatically
2603+ // populate from the WordList.
2604+ // Note: WordList updates are handled by collecting all new words
2605+ // and adding them to the WordList.Items array later.
2606+
2607+ // CRITICAL: Remove xsi:nil from CaptionAndImage for WordList cells
2608+ // Even though the cell populates from WordList, the xsi:nil attribute
2609+ // tells Grid 3 to display it as blank. We need to remove it so Grid 3
2610+ // will show the WordList content.
2611+ if ( cell . Content . CaptionAndImage || cell . Content . captionAndImage ) {
2612+ const captionAndImage = cell . Content . CaptionAndImage || cell . Content . captionAndImage ;
2613+ if ( captionAndImage [ '@_xsi:nil' ] || captionAndImage [ 'xsi:nil' ] ) {
2614+ delete captionAndImage [ '@_xsi:nil' ] ;
2615+ delete captionAndImage [ 'xsi:nil' ] ;
2616+ }
2617+ }
2618+
2619+ continue ; // Skip further cell modification for WordList cells
2620+ }
2621+
2622+ // For regular cells, update the caption directly
25962623 if ( cell . Content . CaptionAndImage || cell . Content . captionAndImage ) {
25972624 const captionAndImage = cell . Content . CaptionAndImage || cell . Content . captionAndImage ;
25982625 captionAndImage . Caption = modifiedButton . label || '' ;
@@ -2605,19 +2632,6 @@ class GridsetProcessor extends BaseProcessor {
26052632 }
26062633 }
26072634
2608- // CRITICAL: Remove ContentType and ContentSubType when adding static content
2609- // Grid 3 sees ContentType="AutoContent" and tries to populate dynamically,
2610- // ignoring the static Caption. We must remove these to show static content.
2611- if ( cell . Content . ContentType === 'AutoContent' ||
2612- cell . Content . ContentSubType === 'WordList' ||
2613- cell . Content . ContentType === 'AutoContent' ||
2614- cell . Content . ContentSubType === 'WordList' ) {
2615- delete cell . Content . ContentType ;
2616- delete cell . Content . ContentSubType ;
2617- delete cell . Content [ 'ContentType' ] ;
2618- delete cell . Content [ 'ContentSubType' ] ;
2619- }
2620-
26212635 // Update the message if different from label
26222636 if ( modifiedButton . message && modifiedButton . message !== modifiedButton . label ) {
26232637 // For simple text content
@@ -2637,6 +2651,64 @@ class GridsetProcessor extends BaseProcessor {
26372651 }
26382652 }
26392653
2654+ // Update the page's WordList with new words from modified buttons
2655+ // Collect all modified buttons that should be added to the WordList
2656+ const newWordListItems : any [ ] = [ ] ;
2657+
2658+ for ( const button of page . buttons ) {
2659+ const pos = this . findButtonPosition ( page , button , 0 ) ;
2660+ const key = `${ pos . x } ,${ pos . y } ` ;
2661+
2662+ // Check if this button corresponds to a WordList cell
2663+ const cellArray = Array . isArray ( originalGrid . Grid . Cells ?. Cell )
2664+ ? originalGrid . Grid . Cells . Cell
2665+ : originalGrid . Grid . Cells ?. Cell
2666+ ? [ originalGrid . Grid . Cells . Cell ]
2667+ : [ ] ;
2668+
2669+ const cell = cellArray . find ( ( c : any ) => {
2670+ const cellX = parseInt ( String ( c [ '@_X' ] || '0' ) , 10 ) ;
2671+ const cellY = parseInt ( String ( c [ '@_Y' ] || '0' ) , 10 ) ;
2672+ return cellX === pos . x && cellY === pos . y ;
2673+ } ) ;
2674+
2675+ if ( cell ) {
2676+ const isWordListCell =
2677+ ( cell . Content ?. ContentType === 'AutoContent' || cell . Content ?. ContentType === 'AutoContent' ) &&
2678+ ( cell . Content ?. ContentSubType === 'WordList' || cell . Content ?. ContentSubType === 'WordList' ) ;
2679+
2680+ if ( isWordListCell ) {
2681+ // Add this button to the WordList
2682+ newWordListItems . push ( {
2683+ Text : { s : { r : button . label } } ,
2684+ } ) ;
2685+ }
2686+ }
2687+ }
2688+
2689+ // Add new items to the existing WordList
2690+ if ( newWordListItems . length > 0 ) {
2691+ const existingWordList = originalGrid . Grid . WordList ;
2692+ if ( existingWordList && existingWordList . Items ) {
2693+ const existingItems = existingWordList . Items . WordListItem ||
2694+ existingWordList . Items . wordlistitem ||
2695+ [ ] ;
2696+ const itemsArray = Array . isArray ( existingItems ) ? existingItems : [ existingItems ] ;
2697+
2698+ // Merge existing and new items
2699+ const allItems = [ ...itemsArray , ...newWordListItems ] ;
2700+
2701+ // Update the WordList
2702+ if ( ! originalGrid . Grid . WordList ) {
2703+ originalGrid . Grid . WordList = { } ;
2704+ }
2705+ if ( ! originalGrid . Grid . WordList . Items ) {
2706+ originalGrid . Grid . WordList . Items = { } ;
2707+ }
2708+ originalGrid . Grid . WordList . Items . WordListItem = allItems ;
2709+ }
2710+ }
2711+
26402712 // Build the updated grid XML and convert to Windows line endings
26412713 let builtXml = gridBuilder . build ( originalGrid ) ;
26422714 // Convert Unix line endings to Windows (\r\n) for Grid 3 compatibility
0 commit comments