Skip to content

Commit e322687

Browse files
authored
Merge pull request #45 from willwade/feature-mutationAPI
fix to not add buttons all the time
2 parents c743f20 + 8bfc638 commit e322687

8 files changed

Lines changed: 34 additions & 11 deletions

src/core/treeStructure.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,23 @@ export class AACPage {
487487
this._pendingMutations.push({ type: 'addButton', button });
488488
}
489489

490+
/**
491+
* Internal load-path button push: adds a button to the page WITHOUT recording a mutation.
492+
* Used by processors during loadIntoTree so the loaded baseline isn't treated as user changes.
493+
* Not part of the public API — consumers should always use addButton.
494+
*/
495+
_loadButton(button: AACButton): void {
496+
this.buttons.push(button);
497+
}
498+
499+
/**
500+
* Discard all recorded mutations on this page.
501+
* Useful as an escape hatch after loadIntoTree if the consumer wants a clean baseline.
502+
*/
503+
clearMutations(): void {
504+
this._pendingMutations = [];
505+
}
506+
490507
/**
491508
* Get the list of pending mutations for this page (read-only)
492509
*/

src/processors/applePanelsProcessor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ class ApplePanelsProcessor extends BaseProcessor {
366366
fontWeight: btn.DisplayImageWeight === 'bold' ? 'bold' : 'normal',
367367
},
368368
});
369-
page.addButton(button);
369+
// Load path: do not record as a user mutation
370+
page._loadButton(button);
370371

371372
if (btn.Rect) {
372373
const rect = this.parseRect(btn.Rect);

src/processors/astericsGridProcessor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,8 @@ class AstericsGridProcessor extends BaseProcessor {
917917
colorConfig,
918918
activeColorSchemeDefinition
919919
);
920-
page.addButton(button);
920+
// Load path: do not record as a user mutation
921+
page._loadButton(button);
921922

922923
const buttonX = element.x || 0;
923924
const buttonY = element.y || 0;

src/processors/dotProcessor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ class DotProcessor extends BaseProcessor {
166166
tree.addPage(page);
167167

168168
// Add a self button so single-node graphs yield one button
169-
page.addButton(
169+
// Load path: do not record as a user mutation
170+
page._loadButton(
170171
new AACButton({
171172
id: `${node.id}_self`,
172173
label: node.label,
@@ -191,7 +192,8 @@ class DotProcessor extends BaseProcessor {
191192

192193
targetPageId: edge.to,
193194
});
194-
fromPage.addButton(button);
195+
// Load path: do not record as a user mutation
196+
fromPage._loadButton(button);
195197
}
196198
}
197199

src/processors/gridsetProcessor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,8 +1749,8 @@ class GridsetProcessor extends BaseProcessor {
17491749
},
17501750
});
17511751

1752-
// Add button to page
1753-
page.addButton(button);
1752+
// Add button to page (load path: do not record as a user mutation)
1753+
page._loadButton(button);
17541754

17551755
// Place button in grid layout (handle colspan/rowspan)
17561756
for (let r = cellY; r < cellY + rowSpan && r < maxRows; r++) {

src/processors/opmlProcessor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class OpmlProcessor extends BaseProcessor {
7878
message: '',
7979
targetPageId: childText.replace(/[^a-zA-Z0-9]/g, '_'),
8080
});
81-
page.addButton(button);
81+
// Load path: do not record as a user mutation
82+
page._loadButton(button);
8283

8384
const { page: childPage, childPages: grandChildren } = this.processOutline(
8485
child,

src/processors/snapProcessor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,8 @@ class SnapProcessor extends BaseProcessor {
705705
// Add to the intended parent page
706706
const parentPage = tree.getPage(parentUniqueId);
707707
if (parentPage) {
708-
parentPage.addButton(button);
708+
// Load path: do not record as a user mutation
709+
parentPage._loadButton(button);
709710

710711
// Add button to grid layout if position data is available
711712
const gridPositionStr = String(btnRow.GridPosition || '');

src/processors/touchchatProcessor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ class TouchChatProcessor extends BaseProcessor {
406406
button.x = absoluteX;
407407
button.y = absoluteY;
408408

409-
// Add button to page
410-
page.addButton(button);
409+
// Add button to page (load path: do not record as a user mutation)
410+
page._loadButton(button);
411411

412412
// Place button in grid (handle span)
413413
for (let r = absoluteY; r < absoluteY + safeSpanY && r < 10; r++) {
@@ -518,7 +518,7 @@ class TouchChatProcessor extends BaseProcessor {
518518
const page = Object.values(tree.pages).find(
519519
(p) => p.id === (numericToRid.get(btnRow.id) || String(btnRow.id))
520520
);
521-
if (page) page.addButton(button);
521+
if (page) page._loadButton(button); // load path: do not record as a user mutation
522522
});
523523
} catch (_e) {
524524
// console.log('No direct page buttons found:', e);

0 commit comments

Comments
 (0)