Skip to content

Commit

Permalink
Adds feature requested in first bullet point of phosphorjs#354
Browse files Browse the repository at this point in the history
  • Loading branch information
telamonian committed Aug 11, 2018
1 parent 57a76ca commit 6a85cdd
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/widgets/src/contextmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ namespace ContextMenu {
* The default rank is `Infinity`.
*/
rank?: number;

/**
* Pass a selected node's dataset to an item's command.
*
* If this flag is set, when a contextmenu item is matched
* to the target of a contextmenu event, the key-value pairs
* in `target.dataset` (if present) will be added as
* properties of `item.args`.
*
* Only meaningful for items of type `command`.
*/
passDataset?: boolean;
}
}

Expand All @@ -190,6 +202,11 @@ namespace Private {
*/
rank: number;

/**
* Pass a selected node's dataset to an item's command.
*/
passDataset: boolean;

/**
* The tie-breaking id for the item.
*/
Expand All @@ -203,7 +220,8 @@ namespace Private {
function createItem(options: ContextMenu.IItemOptions, id: number): IItem {
let selector = validateSelector(options.selector);
let rank = options.rank !== undefined ? options.rank : Infinity;
return { ...options, selector, rank, id };
let passDataset = options.passDataset !== undefined ? options.passDataset : false;
return { ...options, selector, rank, passDataset, id };
}

/**
Expand Down Expand Up @@ -266,6 +284,11 @@ namespace Private {
continue;
}

// Pass the target's dataset to the matched item's args, if requested.
if (item.passDataset && 'dataset' in target) {
item.args = {...item.args, ...(target as any)['dataset']};
}

// Add the matched item to the result for this DOM level.
matches.push(item);

Expand Down

0 comments on commit 6a85cdd

Please sign in to comment.