Declaring commands
Declare commands in thecardCommands field of mnaddon.json.
mnaddon.json
ididentifies the command. Templates reference the command by this value.titleis the text shown in the menu. It can be a string, or an object keyed by language with the text as value. Keys arezh-Hans,zh-Hant,en, and so on.whennarrows down which cards show the command. Omit it to show the command on every card.
Conditions and condition groups
when decides whether the command appears in the menu. The evaluation never runs the add-on’s page code, so only existing card data and fields previously written by add-ons are available. The conditions fall into the following categories.
To test a field written by an add-on, use addonValue. It can compare the value or check whether the field exists:
See Special cases below for how
addonValue is written.hashtagtests whether the card carries the given hashtag.hasTitletests whether the card has a title.hasChildrentests whether the card has child cards in the mind map.hasExcerpttests whether the card carries content excerpted from a document. It means the same assourceAnchor.hasExcerptin abatch-getresponse.
parent, child, and descendant. They are satisfied when the parent card, a child card, or any card further down satisfies the nested condition.
Combining conditions
Conditions combine withand, or, and not. and requires every condition in the array to hold; or requires at least one; not requires the nested condition to fail. and and or take an array of conditions.These groups nest freely: any entry in an array can itself be another group.
Example 1
Thebranch command below appears only when the card has neither the #practice/question nor the #practice/answer hashtag, and none of its child cards carry #practice/answer either.
mnaddon.json
Example 2
Thechoose_sense command below appears when either the card’s status field equals pending, or the card has no status field and carries the #VocabPending hashtag:
mnaddon.json
Special cases
If the decision depends on something none of the conditions above can express, store the outcome in a card field first and let the menu test that field:Adding commands to menus
Declaring a command in the add-on is only half the work; the template has to add it to a menu. The template’sselectionMenu field registers MN’s popup menus.
cardsis the card menu, shown when you click a card in the mind map or outline.documentsis the card menu in documents, shown when you click a card that came from an excerpt.textis the text selection menu, shown when you select text in a document.
addon.<addon-id>.<command-id>: to that menu’s array. The trailing colon is required.
template.json
Receiving commands
The page does not need to registercardCommand in events. Just listen for it in the page code:
index.html
If the add-on panel is fully closed when the user clicks a command, MN first opens the panel in
mini mode, then pushes the command event.