Bike 2.0 (Preview 219)

  • Added fetch (fetch permission) API
  • Added outlineEditor.observeSelection API
  • Added window.observeCurrentOutlineEditor API
  • Added more editor API for folding and focus testing
  • Changed some fields in outlineEditor.selection
  • Removed network access in DOMScripts (fetch should always fail)

I have added an example inspector item to the @Bike extension that puts these
changes together. To try it out fully select a word in your outline. You should
see a list of synonyms show in the inspector. Dig into the @Bike extension to
see how it works… but the basic idea is fetch happens in the app context and requires the fetch permission. It sends results to the DOMScript context.

Next step, when you click on a synonym it should replace the selected word in outline.

Questions welcome!

Download:

1 Like

Am I right in thinking that in Preview 219 Go > Open link ⇧⌘O (and clicking on link icons) are asleep for the moment ?

Yes, lots of UI still not connected. Also find panel. Context menus, etc.

1 Like

Just had a thought… in recent release I also added API for URL.open. Should be possible to implement Open Link in extension code now.

1 Like

Good exercise for experimentation – I’ll try : -)


UPDATE

I like the synonyms example in (Preview 219 > Show Inspector > select word) :slight_smile:


Defined in:

Preview 219 > Bike > Extensions... > @Bike/src/main.ts >
bikeObserveWindows > fetchSynonymsAndPostToDOM

Looking at Creating Extensions | Bike, and just checking that I have understood which string values are valid for the source key in:

  • .addCommands
  • .addKeyBinding

these are essentially the name of the source extension, without the @ prefix ?

(I notice, in the example, that the CommandSource value in the example starts with a capital letter, while the KeybindingSource value is all lower case. Should we follow that pattern, or is the value matching case-insensitive ?)


A separate question: is there any way of listing the keybindings (and commands) that are currently defined by JS extensions in a given context (editor or dom) ?

I am finding, with the rough draft @Startup below:

Expand disclosure triangle to view TS source
import { AppExtensionContext } from "bike";


function toggleCollapseCommand(): boolean {
    const
        editor = bike.frontmostOutlineEditor,
        selnRows = editor?.selection!.rows;

    return selnRows
        ? (
            // Effect
            editor.isCollapsed(selnRows[0])
                ? editor.expand(selnRows, "completely")
                : editor.collapse(selnRows, "row"),
            // Value
            true
        )
        : false;
};

export function activate(context: AppExtensionContext) {
    bike.commands.addCommands({
        source: "startup",
        commands: {
            "startup:toggle-collapse": toggleCollapseCommand
        }
    });

    bike.keybindings.addKeybindings({
        keymap: "block-mode",
        source: "startup",
        keybindings: {
            "t c": "startup:toggle-collapse",
        }
    });

    // bike.keybindings.addKeybindings({
    //     keymap: "text-mode",
    //     source: "startup",
    //     keybindings: {
    //         "cmd+e": "startup:toggle-collapse",
    //     }
    // });

    console.log("Defined ?")
}

That I can trigger startup:toggle-collapse either:

  1. in the Safari console with bike.commands.performCommand("startup:toggle-collapse"), or
  2. in Bike 2 Preview (219) block mode with t c,

but I don’t seem to be succeeding in binding a key to it text mode (see .addKeyBindings snippet commented out in the draft above).

Not sure whether this is because toggling collapse is more a block mode operation than a text mode edit, or whether I am just getting something else wrong.

This added sidebar view had me thinking…is it possible to build a calendar view with this that would work in conjunction with the Today shortcut flow? Basically a calendar picker for the corresponding day row?