Outliner

The port plan

Outliner is a port of Logseq to ztcl and ztk. The reference is the tag 0.10.9 of Logseq, the last line with the file graph. This page maps each feature to the Logseq module that it follows and to the Outliner file that has it. It also gives the order of the work and the design of each part.

Scope

The features and their modules

FeatureLogseq module (tag 0.10.9)Outliner fileState
Markdown and Org blocksdeps/graph-parser (mldoc.cljc, block.cljs, extract.cljc), the mldoc parsersrc/lib/fmt.tclDone
Properties, markers, priorities, timestampsgraph_parser/property.cljs, block.cljs, text.cljssrc/lib/block.tclDone
Inline markupmldoc inline, components/block.cljssrc/lib/block.tcl (inline)Done
Page names and file namesgraph_parser/util.cljs (title-parsing, page-name-sanity), common/util.cljssrc/lib/graph.tclDone
Journal datesgraph_parser/date_time_util.cljs, frontend/date.cljssrc/lib/date.tclDone
config.edngraph_parser/config.cljs, frontend/config.cljssrc/lib/edn.tcl, src/lib/graph.tclDone for the keys in Config keys
The block tree and its editsmodules/outliner/core.cljs, tree.cljssrc/lib/outline.tclDone
Undo and redomodules/editor/undo_redo.cljssrc/lib/graph.tcl (transactions)Done
Save to filesmodules/file/core.cljs, handler/file.cljssrc/lib/graph.tcl (text, flush)Done
The index: references, block ids, aliasesDataScript with deps/db/schema.cljssrc/lib/graph.tcl (index arrays and the cache)Done
The editorhandler/editor.cljs, components/editor.cljssrc/ui/edit.tclDone
Block renderingcomponents/block.cljssrc/ui/view.tclDone
The slash menu and the < menucommands.cljssrc/ui/popup.tclDone
Page and block completionhandler/editor.cljs (search popups)src/ui/popup.tclDone
Keyboard shortcutsmodules/shortcut/config.cljssrc/ui/edit.tcl, src/ui/app.tclDone for the editor and the window
Page view, linked and unlinked referencescomponents/page.cljs, components/reference.cljssrc/ui/view.tclDone
Block references and embedscomponents/block.cljs (block-reference, block-embed, page-embed)src/ui/view.tclDone
Journalscomponents/journal.cljs, handler/journal.cljssrc/ui/view.tclDone
Templateshandler/editor.cljs (template-on-chosen-handler), commands.cljssrc/ui/popup.tclDone
Searchsearch.cljs, search/src/lib/graph.tcl (search), src/ui/app.tclDone
Simple queriesdb/query_dsl.cljssrc/lib/query.tclDone
Advanced queriesDataScript Datalog, db/query_react.cljs, db/rules.cljcsrc/lib/datalog.tclDone, with the limits in Advanced queries
The right sidebarcomponents/right_sidebar.cljssrc/ui/app.tclDone
The graph viewcomponents/page.cljs (global-graph), extensions/graph (pixi)src/ui/graphview.tclDone
Themescomponents/theme.cljs, the CSS variablessrc/ui/theme.tclDone
Exporthandler/export/ (text.cljs, html.cljs, opml.cljs)src/lib/export.tclDone
Pluginshandler/plugin.cljs, libs/ (the JavaScript SDK)src/lib/plugin.tcl, src/ui/dialogs.tclDone, in a sandbox inside the app. A virtual machine for each plugin waits for ztk
The DB graphdeps/db, deps/outliner on masternone yetNot started. The ztk program has no SQLite package

The order of the work

Each phase leaves a program that a person can use.

  1. a. The file graph. The parser, the page names, the index, the outline edits, undo, and save. The tests check that a file with no edit has the same bytes after a save.
  2. b. The editor. Blocks in a ztk text widget, with the keys of Logseq.
  3. c. Links. References, backlinks, block references, embeds, tags, journals.
  4. d. Search and queries.
  5. e. The graph view, the sidebar, the themes, and export.
  6. f. Plugins. Tcl plugins in safe interpreters and WebAssembly plugins, each with grants per document and an activity report.
  7. g. The DB variant.

The design of each part

The parser

A file is a list of chunks. A chunk is one block, or the text before the first block. Each chunk keeps its source text. A save writes the source text of each chunk with no edit, so a file with no edit keeps each byte. A block with an edit is written again from its level and its content, with the indent unit of the file (a tab, or the spaces that the file uses). A file with an irregular indent is written again as a whole on its first edit.

One regular expression finds each line that can start a Markdown block (- after spaces or tabs). The text between two starts is one block. A code fence can contain such a line, so a block with a fence is checked line by line. Org blocks start at a headline.

The content of a block is its text with the bullet and the continuation indent removed. ol::block::analyze gives the marker, the priority, the properties, the references, the tags, the block references, and the timestamps of a content.

The data model

Logseq keeps each block and page in DataScript. Outliner keeps Tcl arrays in ol::graph:

An edit runs in a transaction. The first change of a file in a transaction stores a snapshot of its blocks. Undo puts the snapshots back.

The index

Opening a graph reads no page. The index has, for each file: the page names that it references, its block ids, its aliases, its title, and its task markers. A scan makes the index with a few regular expressions for each file, in steps, while the window is in use. The index goes in a cache file with the time and the size of each file, so the next start scans only the files with a change. A page is parsed when a view, a reference list, or a query needs its blocks.

The widgets

One ztk text widget is one view. A view has rows: a title, a block, a header, a breadcrumb. A row is a range of lines with one mark at its start. The block rows have the rendered text with tags for the styles. The row of the focused block has its source text, and the text widget edits it with its own keys, caret, selection, and input method. The editor code keeps the caret inside the row and handles the keys that change the tree.

After a change, a view builds its list of rows again. With the same list, it renders only the rows with new content. With a new list, it renders all rows in one insert call. The text widget lays out only the lines in the window, so a long view scrolls at the same speed as a short one.

The popups (slash menu, completion), the search, and the command list are listbox widgets in a placed frame. The graph view is a canvas.

Advanced queries

src/lib/datalog.tcl has the engine: data patterns, predicates, functions, not, or, and, user rules, the rules of Logseq (task, page-ref, property, between, and the others), :in with :inputs, and aggregates in :find. An entity is a block or a page. The attributes are computed from the blocks, with no stored datoms.

Limits:

Config keys

:preferred-format, :preferred-workflow, :journal/page-title-format, :journal/file-name-format, :pages-directory, :journals-directory, :file/name-format, :favorites, :default-queries, :default-templates, and :macros.

Plugins

A Tcl plugin runs in a safe interpreter and asks the app with data requests. A WebAssembly plugin runs through ztcl::wasm with host functions for the same API. The app checks each call against the grants, the scope, and the private rules, and writes it to an activity log with a hash chain. Each plugin is off until the user turns it on for a page or for the graph. The plugin API has the details.

The DB variant

The DB graph of Logseq keeps blocks in SQLite. The plan is the same ol::graph API on a second store, with the schema of deps/db. The ztk program accepts the capability sqlite and has no sqlite3 package, so this phase is not started.