Skip to content

Commit c27b5e9

Browse files
Notes: Restore note-ID metadata helpers on the suggest-mode stack
The suggest-mode stack diverged from trunk before #75147 landed, so addNoteIdToMetadata and getNoteIdsFromMetadata are absent from this branch's collab-sidebar/utils.js. suggestion-mode/provider.js imports both, breaking the JS bundle build (esbuild: no matching export) and cascading into the PHP, Playwright, and release checks. Vendor the two pure helpers verbatim from trunk (786c69c) so this PR builds independently of a full-stack rebase. They resolve cleanly against trunk's identical definitions when the stack is updated.
1 parent f4a88e2 commit c27b5e9

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

  • packages/editor/src/components/collab-sidebar

packages/editor/src/components/collab-sidebar/utils.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,42 @@ export function scrollNoteThreadIntoView( noteId, container ) {
344344
element?.scrollIntoView( { block: 'nearest' } );
345345
} );
346346
}
347+
348+
/**
349+
* Reads the note IDs from block metadata as a normalized array,
350+
* preserving insertion order. Handles both scalar (legacy, possibly
351+
* string-typed) and array (new) values.
352+
*
353+
* @param {Object} metadata Block metadata object
354+
* @return {number[]} Array of note IDs (may be empty)
355+
*/
356+
export function getNoteIdsFromMetadata( metadata ) {
357+
const noteId = metadata?.noteId;
358+
const raw = Array.isArray( noteId ) ? noteId : [ noteId ];
359+
const ids = new Set();
360+
for ( const value of raw ) {
361+
const id = Number( value );
362+
if ( Number.isFinite( id ) && id > 0 ) {
363+
ids.add( id );
364+
}
365+
}
366+
return [ ...ids ];
367+
}
368+
369+
/**
370+
* Adds a note ID to the metadata.
371+
* Converts scalar to array if needed, otherwise appends.
372+
*
373+
* @param {Object} metadata Existing block metadata
374+
* @param {number} noteId Note ID to add
375+
* @return {Object} Updated metadata object
376+
*/
377+
export function addNoteIdToMetadata( metadata, noteId ) {
378+
const ids = new Set( getNoteIdsFromMetadata( metadata ) );
379+
const id = Number( noteId );
380+
if ( ids.has( id ) ) {
381+
return metadata;
382+
}
383+
ids.add( id );
384+
return { ...metadata, noteId: [ ...ids ] };
385+
}

0 commit comments

Comments
 (0)