Skip to content

Commit d055691

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 7276c39 commit d055691

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
@@ -275,3 +275,42 @@ export function scrollNoteThreadIntoView( noteId, container ) {
275275
element?.scrollIntoView( { block: 'nearest' } );
276276
} );
277277
}
278+
279+
/**
280+
* Reads the note IDs from block metadata as a normalized array,
281+
* preserving insertion order. Handles both scalar (legacy, possibly
282+
* string-typed) and array (new) values.
283+
*
284+
* @param {Object} metadata Block metadata object
285+
* @return {number[]} Array of note IDs (may be empty)
286+
*/
287+
export function getNoteIdsFromMetadata( metadata ) {
288+
const noteId = metadata?.noteId;
289+
const raw = Array.isArray( noteId ) ? noteId : [ noteId ];
290+
const ids = new Set();
291+
for ( const value of raw ) {
292+
const id = Number( value );
293+
if ( Number.isFinite( id ) && id > 0 ) {
294+
ids.add( id );
295+
}
296+
}
297+
return [ ...ids ];
298+
}
299+
300+
/**
301+
* Adds a note ID to the metadata.
302+
* Converts scalar to array if needed, otherwise appends.
303+
*
304+
* @param {Object} metadata Existing block metadata
305+
* @param {number} noteId Note ID to add
306+
* @return {Object} Updated metadata object
307+
*/
308+
export function addNoteIdToMetadata( metadata, noteId ) {
309+
const ids = new Set( getNoteIdsFromMetadata( metadata ) );
310+
const id = Number( noteId );
311+
if ( ids.has( id ) ) {
312+
return metadata;
313+
}
314+
ids.add( id );
315+
return { ...metadata, noteId: [ ...ids ] };
316+
}

0 commit comments

Comments
 (0)