@@ -1122,12 +1122,13 @@ function buildInserterItemFromBlockType( state, enabledBlockTypes, blockType ) {
1122
1122
/**
1123
1123
* Given a reusable block, constructs an item that appears in the inserter.
1124
1124
*
1125
+ * @param {Object } state Global application state.
1125
1126
* @param {string[]|boolean } enabledBlockTypes Enabled block types, or true/false to enable/disable all types.
1126
1127
* @param {Object } reusableBlock Reusable block, likely from getReusableBlock().
1127
1128
*
1128
1129
* @return {Editor.InserterItem } Item that appears in inserter.
1129
1130
*/
1130
- function buildInserterItemFromReusableBlock ( enabledBlockTypes , reusableBlock ) {
1131
+ function buildInserterItemFromReusableBlock ( state , enabledBlockTypes , reusableBlock ) {
1131
1132
if ( ! enabledBlockTypes || ! reusableBlock ) {
1132
1133
return null ;
1133
1134
}
@@ -1137,7 +1138,12 @@ function buildInserterItemFromReusableBlock( enabledBlockTypes, reusableBlock )
1137
1138
return null ;
1138
1139
}
1139
1140
1140
- const referencedBlockType = getBlockType ( reusableBlock . type ) ;
1141
+ const referencedBlock = getBlock ( state , reusableBlock . uid ) ;
1142
+ if ( ! referencedBlock ) {
1143
+ return null ;
1144
+ }
1145
+
1146
+ const referencedBlockType = getBlockType ( referencedBlock . name ) ;
1141
1147
if ( ! referencedBlockType ) {
1142
1148
return null ;
1143
1149
}
@@ -1173,7 +1179,7 @@ export function getInserterItems( state, enabledBlockTypes = true ) {
1173
1179
) ;
1174
1180
1175
1181
const dynamicItems = getReusableBlocks ( state ) . map ( reusableBlock =>
1176
- buildInserterItemFromReusableBlock ( enabledBlockTypes , reusableBlock )
1182
+ buildInserterItemFromReusableBlock ( state , enabledBlockTypes , reusableBlock )
1177
1183
) ;
1178
1184
1179
1185
const items = [ ...staticItems , ...dynamicItems ] ;
@@ -1201,7 +1207,7 @@ function getItemsFromInserts( state, inserts, enabledBlockTypes = true, maximum
1201
1207
const items = fillWithCommonBlocks ( inserts ) . map ( insert => {
1202
1208
if ( insert . ref ) {
1203
1209
const reusableBlock = getReusableBlock ( state , insert . ref ) ;
1204
- return buildInserterItemFromReusableBlock ( enabledBlockTypes , reusableBlock ) ;
1210
+ return buildInserterItemFromReusableBlock ( state , enabledBlockTypes , reusableBlock ) ;
1205
1211
}
1206
1212
1207
1213
const blockType = getBlockType ( insert . name ) ;
@@ -1248,8 +1254,8 @@ export function getFrecentInserterItems( state, enabledBlockTypes = true, maximu
1248
1254
/**
1249
1255
* Returns the reusable block with the given ID.
1250
1256
*
1251
- * @param {Object } state Global application state.
1252
- * @param {string } ref The reusable block's ID.
1257
+ * @param {Object } state Global application state.
1258
+ * @param {number| string } ref The reusable block's ID.
1253
1259
*
1254
1260
* @return {Object } The reusable block, or null if none exists.
1255
1261
*/
@@ -1260,10 +1266,12 @@ export const getReusableBlock = createSelector(
1260
1266
return null ;
1261
1267
}
1262
1268
1269
+ const isTemporary = isNaN ( parseInt ( ref ) ) ;
1270
+
1263
1271
return {
1264
1272
...block ,
1265
- id : ref ,
1266
- isTemporary : ! Number . isInteger ( ref ) ,
1273
+ id : isTemporary ? ref : + ref ,
1274
+ isTemporary,
1267
1275
} ;
1268
1276
} ,
1269
1277
( state , ref ) => [
@@ -1304,7 +1312,7 @@ export function isFetchingReusableBlock( state, ref ) {
1304
1312
* @return {Array } An array of all reusable blocks.
1305
1313
*/
1306
1314
export function getReusableBlocks ( state ) {
1307
- return Object . values ( state . reusableBlocks . data ) ;
1315
+ return Object . keys ( state . reusableBlocks . data ) . map ( ( ref ) => getReusableBlock ( state , ref ) ) ;
1308
1316
}
1309
1317
1310
1318
/**
0 commit comments