@@ -167,6 +167,18 @@ namespace ContextMenu {
167167 * The default rank is `Infinity`.
168168 */
169169 rank ?: number ;
170+
171+ /**
172+ * Pass a selected node's dataset to an item's command.
173+ *
174+ * If this flag is set, when a contextmenu item is matched
175+ * to the target of a contextmenu event, the key-value pairs
176+ * in `target.dataset` (if present) will be added as
177+ * properties of `item.args`.
178+ *
179+ * Only meaningful for items of type `command`.
180+ */
181+ passDataset ?: boolean ;
170182 }
171183}
172184
@@ -190,6 +202,11 @@ namespace Private {
190202 */
191203 rank : number ;
192204
205+ /**
206+ * Pass a selected node's dataset to an item's command.
207+ */
208+ passDataset : boolean ;
209+
193210 /**
194211 * The tie-breaking id for the item.
195212 */
@@ -203,7 +220,8 @@ namespace Private {
203220 function createItem ( options : ContextMenu . IItemOptions , id : number ) : IItem {
204221 let selector = validateSelector ( options . selector ) ;
205222 let rank = options . rank !== undefined ? options . rank : Infinity ;
206- return { ...options , selector, rank, id } ;
223+ let passDataset = options . passDataset !== undefined ? options . passDataset : false ;
224+ return { ...options , selector, rank, passDataset, id } ;
207225 }
208226
209227 /**
@@ -266,6 +284,11 @@ namespace Private {
266284 continue ;
267285 }
268286
287+ // Pass the target's dataset to the matched item's args, if requested.
288+ if ( item . passDataset && 'dataset' in target ) {
289+ item . args = { ...item . args , ...( target as any ) [ 'dataset' ] } ;
290+ }
291+
269292 // Add the matched item to the result for this DOM level.
270293 matches . push ( item ) ;
271294
0 commit comments