1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-20 00:34:50 +00:00
TiddlyWiki5/archive/tiddlywiki5/store/MacroInternals.tid

41 lines
1.9 KiB
Plaintext
Raw Normal View History

2012-01-15 11:46:20 +00:00
title: MacroInternals
2012-02-10 11:12:20 +00:00
! Macro Fields
2012-02-11 17:11:23 +00:00
Macros are implemented as conventional JavaScript modules that export a single variable called `macro` that contains these fields:
2012-01-15 11:46:20 +00:00
|!Field Name |!Description |
|`name` |The name of the macro |
|`params` |A hashmap of the parameters accepted by the macro (see below) |
2012-02-10 11:12:20 +00:00
|`events` |An optional hashmap of event handling functions (see below) |
2012-03-03 18:06:24 +00:00
|`execute` |The macro rendering function (see below) |
|`refreshInDom` |The optional macro rerendering function (see below) |
2012-02-10 11:12:20 +00:00
|`dependentAll` |True if the macro needs access to all available tiddlers |
2012-01-15 11:46:20 +00:00
2012-02-10 11:12:20 +00:00
! Macro Parameters
2012-01-15 11:46:20 +00:00
The `params` hashmap provides the following fields about each parameter:
|!Param Field Name |!Description |
2012-02-10 11:12:20 +00:00
|`byName` |Provided if the parameter should be referenced by name. The value can be `true` or `"default"` to indicate that anonymous parameters are acceptable |
2012-03-03 18:06:24 +00:00
|`byPos` |Provided if the parameter should be referenced by its numerical position (0-based) |
2012-02-10 11:12:20 +00:00
|`type` |The type of the parameter, either `text` or `tiddler` (used for dependency tracking) |
2012-03-03 18:06:24 +00:00
|`skinny` |True if the parameter is only dependent on the skinny fields of the target tiddler. The default is `false` which means that the target tiddler is treated as a fat dependency |
2012-01-15 11:46:20 +00:00
2012-02-10 11:12:20 +00:00
! Macro Rendering
2012-03-03 18:06:24 +00:00
The `execute` function should prepare the macro output. It is invoked with `this` pointing to the MacroNode object representing this macro invocation.
2012-02-10 11:12:20 +00:00
!Macro Rerendering
2012-03-03 18:06:24 +00:00
The `refreshInDom` function is called with the following parameters:
2012-01-15 11:46:20 +00:00
|!Param Name |!Description |
2012-02-10 11:12:20 +00:00
|`changes` |Hashmap of `{title: "created|modified|deleted"}` |
!Macro Event Handlers
Event handlers are called with the following parameters:
|!Param Name |!Description |
|`event` |The DOM node containing the existing rendering of the macro |
Event handlers should return `false` if they handle the event (and generally should also call `event.preventDefault()`), and `true` if they do not.