@@ -242,11 +242,10 @@ class Publisher {
242242 submitobj . ProjectID = id ;
243243 submitobj . ProjectName = title . value ;
244244 submitobj . ProjectDescription = description . value ;
245- //TODO: Convert these into real block names once integrated into MB
246- //let obj = palettes.getProtoNameAndPalette("MIDI");
247- //console.log(obj[0]);
248- //console.log(obj[1]);
249- //console.log(obj[2]);
245+ // parseProject() now resolves proto block names to display names when running
246+ // inside Music Blocks iframe by accessing window.parent.activity.blocks.palettes.
247+ // This improves project searchability by using human-friendly names (e.g., "pitch"
248+ // display name) instead of proto identifiers in ProjectSearchKeywords.
250249 submitobj . ProjectSearchKeywords = this . parseProject ( this . ProjectTable [ id ] . ProjectData ) ;
251250 submitobj . ProjectData = Planet . ProjectStorage . encodeTB (
252251 this . ProjectTable [ id ] . ProjectData
@@ -291,6 +290,17 @@ class Publisher {
291290 }
292291 }
293292
293+ /**
294+ * parseProject(tb)
295+ * Convert project TB to a space-separated list of block names suitable for
296+ * ProjectSearchKeywords. When possible (i.e., when running inside the main
297+ * Music Blocks iframe) attempt to map proto names to human-friendly display
298+ * names using the palettes API (getProtoNameAndPalette). If palettes are not
299+ * available fall back to the raw proto names.
300+ *
301+ * @param {string } tb - JSON string of project blocks
302+ * @returns {string } space-separated block names
303+ */
294304 parseProject ( tb ) {
295305 try {
296306 tb = JSON . parse ( tb ) ;
@@ -305,9 +315,38 @@ class Publisher {
305315 for ( let i = 0 ; i < tb . length ; i ++ ) {
306316 const block = tb [ i ] ;
307317
308- if ( typeof block [ 1 ] === "string" ) words . add ( block [ 1 ] ) ;
309- else if ( Array . isArray ( block [ 1 ] ) ) words . add ( block [ 1 ] [ 0 ] ) ;
310- else if ( typeof block [ 1 ] === "number" ) break ;
318+ let name = null ;
319+
320+ if ( typeof block [ 1 ] === "string" ) {
321+ name = block [ 1 ] ;
322+ } else if ( Array . isArray ( block [ 1 ] ) ) {
323+ name = block [ 1 ] [ 0 ] ;
324+ } else if ( typeof block [ 1 ] === "number" ) {
325+ break ;
326+ }
327+
328+ if ( name === null ) continue ;
329+
330+ // Best-effort resolution: if running inside the iframe and the parent
331+ // window exposes the Activity palette API, map proto name to the
332+ // human-friendly display name. This ensures Publisher sends meaningful
333+ // keywords for search when integrated with Music Blocks.
334+ try {
335+ if (
336+ typeof window !== "undefined" &&
337+ window . parent &&
338+ window . parent . activity &&
339+ window . parent . activity . blocks &&
340+ window . parent . activity . blocks . palettes
341+ ) {
342+ const p = window . parent . activity . blocks . palettes . getProtoNameAndPalette ( name ) ;
343+ if ( p && p [ 2 ] ) name = p [ 2 ] ;
344+ }
345+ } catch ( e ) {
346+ // ignore and use raw name
347+ }
348+
349+ words . add ( name ) ;
311350 }
312351
313352 let s = "" ;
0 commit comments