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 file graph: a folder of Markdown and Org files. This is the main target.
- The DB graph (the schema of Logseq on SQLite) is a later phase. The DB variant has its state.
- Plugins are Tcl scripts or WebAssembly modules. Outliner runs no JavaScript.
- Not in scope: whiteboards, PDF annotation, flashcards, Zotero, the sync service, and the mobile apps.
The features and their modules
| Feature | Logseq module (tag 0.10.9) | Outliner file | State |
|---|---|---|---|
| Markdown and Org blocks | deps/graph-parser (mldoc.cljc, block.cljs, extract.cljc), the mldoc parser | src/lib/fmt.tcl | Done |
| Properties, markers, priorities, timestamps | graph_parser/property.cljs, block.cljs, text.cljs | src/lib/block.tcl | Done |
| Inline markup | mldoc inline, components/block.cljs | src/lib/block.tcl (inline) | Done |
| Page names and file names | graph_parser/util.cljs (title-parsing, page-name-sanity), common/util.cljs | src/lib/graph.tcl | Done |
| Journal dates | graph_parser/date_time_util.cljs, frontend/date.cljs | src/lib/date.tcl | Done |
config.edn | graph_parser/config.cljs, frontend/config.cljs | src/lib/edn.tcl, src/lib/graph.tcl | Done for the keys in Config keys |
| The block tree and its edits | modules/outliner/core.cljs, tree.cljs | src/lib/outline.tcl | Done |
| Undo and redo | modules/editor/undo_redo.cljs | src/lib/graph.tcl (transactions) | Done |
| Save to files | modules/file/core.cljs, handler/file.cljs | src/lib/graph.tcl (text, flush) | Done |
| The index: references, block ids, aliases | DataScript with deps/db/schema.cljs | src/lib/graph.tcl (index arrays and the cache) | Done |
| The editor | handler/editor.cljs, components/editor.cljs | src/ui/edit.tcl | Done |
| Block rendering | components/block.cljs | src/ui/view.tcl | Done |
The slash menu and the < menu | commands.cljs | src/ui/popup.tcl | Done |
| Page and block completion | handler/editor.cljs (search popups) | src/ui/popup.tcl | Done |
| Keyboard shortcuts | modules/shortcut/config.cljs | src/ui/edit.tcl, src/ui/app.tcl | Done for the editor and the window |
| Page view, linked and unlinked references | components/page.cljs, components/reference.cljs | src/ui/view.tcl | Done |
| Block references and embeds | components/block.cljs (block-reference, block-embed, page-embed) | src/ui/view.tcl | Done |
| Journals | components/journal.cljs, handler/journal.cljs | src/ui/view.tcl | Done |
| Templates | handler/editor.cljs (template-on-chosen-handler), commands.cljs | src/ui/popup.tcl | Done |
| Search | search.cljs, search/ | src/lib/graph.tcl (search), src/ui/app.tcl | Done |
| Simple queries | db/query_dsl.cljs | src/lib/query.tcl | Done |
| Advanced queries | DataScript Datalog, db/query_react.cljs, db/rules.cljc | src/lib/datalog.tcl | Done, with the limits in Advanced queries |
| The right sidebar | components/right_sidebar.cljs | src/ui/app.tcl | Done |
| The graph view | components/page.cljs (global-graph), extensions/graph (pixi) | src/ui/graphview.tcl | Done |
| Themes | components/theme.cljs, the CSS variables | src/ui/theme.tcl | Done |
| Export | handler/export/ (text.cljs, html.cljs, opml.cljs) | src/lib/export.tcl | Done |
| Plugins | handler/plugin.cljs, libs/ (the JavaScript SDK) | src/lib/plugin.tcl, src/ui/dialogs.tcl | Done, in a sandbox inside the app. A virtual machine for each plugin waits for ztk |
| The DB graph | deps/db, deps/outliner on master | none yet | Not started. The ztk program has no SQLite package |
The order of the work
Each phase leaves a program that a person can use.
- 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.
- b. The editor. Blocks in a ztk text widget, with the keys of Logseq.
- c. Links. References, backlinks, block references, embeds, tags, journals.
- d. Search and queries.
- e. The graph view, the sidebar, the themes, and export.
- f. Plugins. Tcl plugins in safe interpreters and WebAssembly plugins, each with grants per document and an activity report.
- 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:
- A block has an integer id, a content, a level, a kind, a file, and its source text. The children of a block are the blocks after it with a higher level, so indent and outdent change levels only.
- A file has the list of its block ids and its format data (line ends, indent unit).
- A page has a name, a file, and a journal day. The key of a page is its name in lower case, as
:block/nameis.
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:
:result-transformand:vieware Clojure code. Outliner knows asort-byof one attribute or property. A Tcl plugin can add a view.- A pattern with a free entity and an attribute with no index reads each block of the graph.
pullpatterns give the whole entity.
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.