Skip to content

Commit bd8c2b7

Browse files
authored
Support block order for buttons (#107)
* add order to button args for keepButton * 1.6.13
1 parent b79d676 commit bd8c2b7

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

docs/060-alternative-methods.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The caption of the button is also available in the SmartBlock workflow under the
5050

5151
## Predefined Variables
5252

53-
There are currently 3 predefined variables: `RemoveButton`, `Clear`, and `Sibling`.
53+
There are currently 5 predefined variables: `RemoveButton`, `Order`, `TargetRef`, `Clear`, and `Sibling`.
5454

5555
### Remove Button
5656

@@ -60,6 +60,26 @@ By default, SmartBlock buttons are removed and the workflow will replace it with
6060

6161
- `{{caption:SmartBlock:workflow name:RemoveButton=false}}`
6262

63+
### Order
64+
65+
When using `RemoveButton` is set to `false`, you can set the `Order` in which to insert the SmartBlock.
66+
67+
Default is 0. (which is first)
68+
Use `last` to target the last block.
69+
70+
**Example**
71+
72+
- `{{caption:SmartBlock:workflow name:RemoveButton=false,Order=last}}`
73+
-
74+
75+
### Target Ref
76+
77+
When using `RemoveButton` is set to `false`, you can set the UID of the block in which to run the SmartBlock on via `TargetRef`.
78+
79+
**Example**
80+
81+
- `{{caption:SmartBlock:workflow name:RemoveButton=false,TargetRef=((kZrX4zMQq))}}`
82+
6383
### Clear
6484

6585
By default, SmartBlock buttons will leave the text as is (of the block the button is running in). If you would like the text of the block cleared, set `Clear` to `true`

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "smartblocks",
3-
"version": "1.6.12",
3+
"version": "1.6.13",
44
"description": "Create custom and programmable templates from within Roam!",
55
"main": "./build/main.js",
66
"scripts": {

src/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,14 @@ export default runExtension(async ({ extensionAPI }) => {
598598
const clearBlock = /true/i.test(variables["Clear"]);
599599
const applyToSibling = variables["Sibling"];
600600
const explicitTargetUid = extractRef(variables["TargetRef"]);
601+
const order =
602+
variables["Order"] === "last"
603+
? "last"
604+
: !variables["Order"]
605+
? 0
606+
: !isNaN(Number(variables["Order"]))
607+
? Number(variables["Order"])
608+
: 0;
601609

602610
const props = {
603611
srcUid,
@@ -672,6 +680,7 @@ export default runExtension(async ({ extensionAPI }) => {
672680
: createBlock({
673681
node: { text: "" },
674682
parentUid,
683+
order,
675684
}).then((targetUid) =>
676685
sbBomb({
677686
...props,

0 commit comments

Comments
 (0)