Skip to content

Commit

Permalink
Support block order for buttons (#107)
Browse files Browse the repository at this point in the history
* add order to button args for keepButton

* 1.6.13
  • Loading branch information
mdroidian authored Nov 6, 2023
1 parent b79d676 commit bd8c2b7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
22 changes: 21 additions & 1 deletion docs/060-alternative-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The caption of the button is also available in the SmartBlock workflow under the

## Predefined Variables

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

### Remove Button

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

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

### Order

When using `RemoveButton` is set to `false`, you can set the `Order` in which to insert the SmartBlock.

Default is 0. (which is first)
Use `last` to target the last block.

**Example**

- `{{caption:SmartBlock:workflow name:RemoveButton=false,Order=last}}`
-

### Target Ref

When using `RemoveButton` is set to `false`, you can set the UID of the block in which to run the SmartBlock on via `TargetRef`.

**Example**

- `{{caption:SmartBlock:workflow name:RemoveButton=false,TargetRef=((kZrX4zMQq))}}`

### Clear

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`
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smartblocks",
"version": "1.6.12",
"version": "1.6.13",
"description": "Create custom and programmable templates from within Roam!",
"main": "./build/main.js",
"scripts": {
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,14 @@ export default runExtension(async ({ extensionAPI }) => {
const clearBlock = /true/i.test(variables["Clear"]);
const applyToSibling = variables["Sibling"];
const explicitTargetUid = extractRef(variables["TargetRef"]);
const order =
variables["Order"] === "last"
? "last"
: !variables["Order"]
? 0
: !isNaN(Number(variables["Order"]))
? Number(variables["Order"])
: 0;

const props = {
srcUid,
Expand Down Expand Up @@ -672,6 +680,7 @@ export default runExtension(async ({ extensionAPI }) => {
: createBlock({
node: { text: "" },
parentUid,
order,
}).then((targetUid) =>
sbBomb({
...props,
Expand Down

0 comments on commit bd8c2b7

Please sign in to comment.