Commit Graph
82 Commits
Author SHA1 Message Date
Zef Hemel 4e23e7a4c6 fix: more caching fixes 2026-05-12 13:45:34 +02:00
Zef Hemel 772757ad27 Fix: widget cache invalidation again
Two hard problems in CS...
2026-05-12 11:51:26 +02:00
Zef Hemel a96a86c0b5 Slightly optimize vertical jiggering by pre-computing all widgets on page load 2026-05-12 09:38:17 +02:00
Zef Hemel 09059aa18a Lint: support rich HTML tooltips
LintDiagnostic adds `messageHtml` (rendered into the hover
  tooltip) and `markClass` (added to the inline range mark)
2026-05-09 12:29:19 +02:00
Zef Hemel a626453262 Offer API to external apps (e.g. Tauri) to properly support drag & dropping of files 2026-05-06 15:06:18 +02:00
Zef Hemel 81dbdae857 Fixes #1955 2026-04-30 10:59:53 +02:00
Zef Hemel 795c248a0c Set some sensible default (fallback) config options when defaults are not yet available (initial index) 2026-04-21 13:06:36 +02:00
Zef Hemel 0c9c07b3e6 Config: schema defaults, UI categories and annotations
`config.define` now propagates schema `default` values, so features like smart quotes no longer need their own fallback constants.

Adds `defineCategory` / `getCategories` for the upcoming configuration  manager UI.
2026-04-21 10:03:40 +02:00
Zef Hemel efd827b721 Implements #510
Extracts almost all codemirror keyboard shortcuts into proper SB
commands so they can be rebound

Bonus: renders prettier versions of keyboard shortcuts on Mac
2026-04-17 16:45:11 +02:00
Zef Hemel c9f93dccde Fixes #1929 2026-04-12 10:33:44 +02:00
Zef Hemel 64898923e1 Restore separate copy path for Lua widgets with cleaner markdown
Specifically for tables using (less rich) markdown syntax when possible
2026-04-09 14:38:10 +02:00
Zef Hemel fbaad6cffb Fix widget glitching
No longer cache widget HTML content just widget heights, either way the
widgets will briefly flash as the widget is recalculated and this saves
storage space and reduces issues in Webkit
2026-04-07 15:42:59 +02:00
Zef Hemel 97e84607e7 Minor layout regression fix 2026-04-07 15:42:59 +02:00
Zef Hemel 5751d5b64f HTML tag Live Preview (second attempt) 2026-04-07 11:30:38 +02:00
Zef Hemel 15317ce821 Refactored Lua expression result rendering
Now produce "markdown" (or <table> tags for tables) instead of pure
HTML. Hopefully doesn't introduce regressions. Added a test suite for
future iterations.
2026-04-06 20:13:25 +02:00
Zef Hemel 8da76f230a Customized implementation of Enter handling for lists
* Fine tunes a few behaviors (like not adding extra newlines, ever
  (should fix #1629))
* When a list item ends with :, it automaticaly indents the next item
* Adds an extensive test suite with various cases

This needs some more testing, but should be a good starting point for
adding more tweaks later.
2026-04-06 15:17:48 +02:00
Zef Hemel 2ad3172568 Revert HTML tags live preview, too many edge cases 2026-04-02 14:36:54 +02:00
Zef Hemel e5f188e59e Tag enhancements
* tag.define now supports a `tagPage` attribute, allowing what page to
  send the user to when clicking on a hash tag in the editor
* index.contentPages() and index.metaPages() are convenience wrappers
  around the index.tag("page") collection that filter on content and
  meta pages respectively.
2026-04-01 08:44:50 +02:00
Zef Hemel dc4e701ddf syntax.define refinements 2026-03-31 15:01:16 +02:00
Zef Hemel dbc95239f6 Fixes #702 implementing Live Preview for HTML tags
This may still have edge cases, but basics should be working.
2026-03-31 11:11:17 +02:00
Zef Hemel 431bf787ac Optimization: chunk up all coding languages
Even though the service worker will proactively cache them in the
browser, the browser will not have to load them, parse them, interpret
them unless these languages are actually used. Less JS to load, less
waiting.
2026-03-28 16:49:24 +01:00
Matouš Jan FialkaandGitHub 203ef99fc7 Improve enhanced task widget (#1905)
* Fix (tasks): Toggle dropdown on re-click and narrow mark decoration range

- Clicking the dropdown icon now dismisses the completion menu if it
  is already open (`closeCompletion`).

- The `data-task-state` mark decoration now covers only the inner state
  text (excluding brackets). This prevents CodeMirror cursor/editing
  issues when the caret is inside the brackets and allows bracket-aware
  CSS styling. Example:

  ```space-style
  [data-task-state="DONE"] { color: green; }
  [data-task-state="PLANNED"] { color: orange; }
  [data-task-state] { font-weight: bold; }
  ```

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Refactor (tasks): Unify task state data attribute to `data-task-state`

Rename `data-state` to `data-task-state` on extended task state spans in
Markdown renderer and update the corresponding places.

Previously the editor (CodeMirror mark decoration) used
`data-task-state` while the widget HTML renderer used `data-state`,
requiring duplicate CSS selectors. Now a single attribute selector works
everywhere (for example tasks rendered using `template.taskItem` also
follow the styling now):

```css
[data-task-state="PLANNED"] { /* cool CSS here */; }
```

Note: Checkbox inputs (`[ ]`/`[x]`/`[X]`) still use `data-state` since
they follow a different code path.

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

---------

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
2026-03-24 08:51:13 +01:00
Zef Hemel 6623daa0a2 More sync engine tests + fixes 2026-03-20 16:10:33 +01:00
d2e24ebae0 Add a dropdown picker for custom task states (#1900)
* Add a dropdown picker for custom task states

Add a dropdown picker for custom task states that appears as a small
triangle next to the `[state]` allowing to quickly switch between
defined states with autocomplete.

States marked as done receive strikethrough styling on the task text.

Each state can be styled individually using the `data-task-state`
attribute, for example:

```space-style
[data-task-state=PLANNED] .sb-task-state {
  color: black;
  background-color: orange;
}
```

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Keep the current task state visible while the dropdown picker is open

Keep the current task state visible while the dropdown picker is open by
disabling built-in filtering and handling it manually — when the state
text exactly matches a known state all options are shown, otherwise
results are filtered by what the user has typed so far.

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Added on-hover completion styling

* Fix: Show all defined task states in the dropdown when clicking the picker on an unrecognized state instead of showing an empty menu

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

---------

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
Co-authored-by: Zef Hemel <zef@zef.me>
2026-03-20 15:09:12 +01:00
Matouš Jan FialkaandGitHub 8f7e525812 Fix mobile tasks, annoying caret jumping and empty widgets on navigation (#1890) 2026-03-17 22:16:58 +01:00
Matouš Jan FialkaandGitHub 4db49239a4 Fix extended task state widget click behavior in widgets (#1889)
* Fix extended task state widget click behavior in widgets

* Add mouse click handler on extended task state span to prevent
  CodeMirror from moving selection to widget source on normal click

* Let `Alt+Click` pass to parent div for the "cursor to source" behavior
  matching simple checkbox `Alt+Click` behavior

* Skip state cycling on `Alt+Click`

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Prevent task state corruption from concurrent cycling on mobile

On mobile, rapid taps on an enhanced task state (e.g. `[PLANNED]`) could
fire multiple events before the first `taskCycleAtPos` completed.  Add
a reentrancy guard to `taskCycleAtPos` so concurrent calls are dropped.

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

---------

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
2026-03-17 13:55:47 +01:00
Zef Hemel 4a411b224d Unrelated code slipped in 2026-03-13 14:58:02 +01:00
Zef Hemel fc2228be1a Make sync requests not blow up when service worker is not activated 2026-03-13 14:54:01 +01:00
Matouš Jan FialkaandGitHub 6d52350640 Fix extended task rendering in widgets (#1882)
* Fix extended task rendering in widgets

This patch addresses several issues.

1. Extended tasks like `[PLANNED]` or `[TODO]` were not rendering
   correctly when generated via widgets. The HTML renderer was producing
   plain text without brackets or proper styling, while simple `[x]`
   tasks worked fine.  The fix produces the same DOM structure as
   CodeMirror producing coherent styling everywhere.

2. Widget checkboxes are not interactive now. Since widget tasks have no
   backing state handler clicking them only caused a misleading visual
   toggle with no effect. The `disabled` attribute prevents this
   confusion and the dimmed appearanceit signals to the user that the
   checkbox is read-only in this context which is the truth.

To see it in action try the following Markdown snippet in SilverBullet:

```
- [x] #foo [att: i]
- [PLANNED] bar #bar [att: i]

${'- [x] #foo [att: i]\n- [PLANNED] bar #bar [att: i]'}
```

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Revert and just prevent widget checkboxes from toggling visually

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Support custom task states in widgets and indexer

Custom task states like `[PLANNED]` or `[IN PROGRESS]` now render
correctly in *widgets*, matching the same DOM structure as CodeMirror
uses in the editor. Widget-rendered tasks that reference a real task
(via `page@pos`) are fully interactive — clicking an extended state
cycles it through the configured states and updates the source task.
Tasks without a reference are disabled to prevent misleading visual
feedback.

The task indexer now respects the `done` flag on custom states defined
via `taskState.define`, so queries like `where not t.done` correctly
exclude tasks in states marked as done. Previously only the built-in
simple tasks (`- [x]` or `- [X]`) states were treated as completed. The
`Task: Remove Completed` command already handled custom done states and
continues to work unchanged.

State cycling now preserves the definition order from `taskState.define`
calls instead of sorting alphabetically. A new `order` field allows
explicit control over the cycle sequence. Without it, states cycle in
definition order. With it, states are sorted by the `order` field value.
This gives users full control over the progression, for example:

    PLANNED --> IN PROGRESS --> FINISHED

The `taskState.define` API now validates its input against a schema:
`name` (string, required), `done` (boolean, optional), and `order`
(number, optional).

The `expandMarkdown` no longer injects "fake" `page@pos` references into
tasks rendered via `widget.markdownBlock` or `widget.new` which was
causing broken links and unwanted interactivity on static task content.

The `task:stateChange` event is dispatched when toggling tasks from
widgets, ensuring Lua listeners (such as some custom completed timestamp
management) fire correctly regardless of where the toggle originates.

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

---------

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
2026-03-13 13:32:26 +01:00
Zef Hemel 19d3328647 lint fixes 2026-03-13 09:24:52 +01:00
Zef Hemel 9581433cd3 Fixes #212: adds footnote support
Based on https://www.markdownlang.com/extended/footnotes.html

* Both "official" [^1] and [^1]: def
* And inline ^[My foot note]

Features:
* Properly parsed in markdown parser
* Syntax highlighting
* Live Preview to ... when on-hover preview of content, on-click moves
  cursor to definition
* Reference completion
* Invalid references are marked
2026-03-13 08:28:43 +01:00
Zef Hemel 4bb258ca71 Fix regression: transclusions were no longer treatin wikilinks as
absolute
2026-03-12 20:08:43 +01:00
Zef Hemel dbcef9e8aa Fix: make sure Edit buttons work even for Lua expressions and code
widgets whose bodies appear multiple times in the same page (previously
always jumped to first).
2026-03-12 14:13:18 +01:00
Matouš Jan FialkaandGitHub 1f7a4d7d66 Fix attribute rendering (#1880)
* Fix table row parser

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Remove all `{[command button]}` remnants

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Render `Attribute` nodes in HTML like CodeMirror does

This patch

- ensures always render `Attribute`,
- produces `sb-attribute` span with sub-spans matching CodeMirror DOM,
- removee `preserveAttributes` from Markdown render options and callers.

Finally the attributes looks the same everywhere (table, text, widget).

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

---------

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
2026-03-12 13:50:09 +01:00
Matouš Jan FialkaandGitHub b83c1e03d2 Fix Markdown table rendering and remove deprecated command button remnants (#1879)
* Fix table row parser

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Remove all `{[command button]}` remnants

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Add tests

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

* Fix extended task rendering in case of following EoL

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>

---------

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
2026-03-12 13:46:48 +01:00
Zef HemelandGitHub 3df11ccf3d Implements custom markdown syntax extensions (EXPERIMENTAL) (#1881)
Alternative implemention of #1727
2026-03-12 13:40:20 +01:00
Zef Hemel 1beb13a134 Fix: regression where multi-line markdown results from Lua directives
would _always_ be rendered as inline.

Added back the old heuristic check.
2026-03-11 14:55:02 +01:00
Zef Hemel a080ee3b15 Optimize bundle size + chunked builds + JIT loading
* Replaced AJV with other JSON schema library
* Turndown and Vim mode (very large) now only loaded when used
* Chunked builds with ESBuild
2026-03-11 10:04:13 +01:00
Zef Hemel d9f4b93795 Eliminate (most) uses of the client global
Also an opportunity to refactor the transclusion code, which had become
very messy
2026-03-10 14:02:05 +01:00
Zef Hemel fd1a81b8d8 Client refactor: move UI related APIs to editor_ui.ts 2026-03-10 12:42:26 +01:00
Zef Hemel 6d33d3d8ac Refactor: extract page/document manager into separate class 2026-03-10 12:33:34 +01:00
Zef Hemel cb9f954bc7 Refactor: extract widget cache from Client class 2026-03-10 12:17:02 +01:00
Zef Hemel 799e27a9b4 Enable biome based formatter and reformat 2026-03-10 09:38:59 +01:00
Zef Hemel cce5b669f6 Merge branch 'main' into to-node 2026-03-10 08:57:58 +01:00
Matouš Jan Fialka 2aaa797bda Improve Lua Widget Rendering
Lua `${...}` expression results are rendered using two parallel paths:

- **HTML path** (display path) for visual display in the editor and
- **Markdown path** (copy path) for the *copy button* output.

Every Lua value is classified as one of:

- **Scalar:** number, string, boolean, or `nil`
- **Empty table:** `{}`
- **Array:** a `LuaTable` with only sequential integer keys (no string keys)
- **Array of tables:** an array where every element is a `LuaTable`
- **Record:** a `LuaTable` with any string key (may also have integer keys)

Scalars are rendered as inline Markdown - wiki links, tags, bold, and
other inline syntax are resolved, `nil` renders as `<span data-empty>`.

Empty tables render as `<table data-table-empty>`.

An array of tables renders as a multi-row `<table>`. Column headers
are the union of all element keys. Each cell value recurses through
the same classification.

An array of scalars (or a mix of scalars and tables) renders as `<ul>`
with one `<li>` per element. Each item value recurses.

A record renders as a single-row `<table>` with one column per key.
Cell values recurse.

Every `<td>` carries `data-table-cell-type` and optionally
`data-table-cell-empty`.  Every `<li>` carries `data-list-item-type` and
optionally `data-list-item-empty`.  The outermost element carries
`data-type`.  These attributes allow CSS styling of rendered widgets.

Nesting is **unlimited**. Tables inside cells, lists inside cells,
tables inside list items all render correctly in HTML.

Scalars render as plain text. Lua `nil` renders as `nil`. Empty tables
render as `*(empty table)*`.

An array of tables renders as a pipe-delimited Markdown table. Nested
values in cells are rendered as Lua literals via `toStringAsync()`
(e.g. `{1, 2, 3}` or `{a = 1}`), since Markdown table cells cannot
contain block-level content.

An array of scalars renders as a Markdown list (`- item`). When a list
item is itself multi-line (a sublist) it uses an empty bullet with
two-space indented content on the next line:

```
- 1
- 2
-
  - nested 1
  - nested 2
```

Nested tables or arrays **beyond the first list nesting** level are
rendered as Lua literals.

A record renders as a single-row Markdown table.

Column headers follow the order returned by `LuaTable.keys`: string keys
in their insertion order, followed by integer keys in ascending order.
For example, `{a = 1, b = 2, 3, d = 4}` produces columns `a
| b | d | 1`. This is consequence of `LuaTable` storing string keys
and the array part separately (for performance).

Arrays mixing plain scalars and record-like tables (e.g.  `{1, 2, 3,
{a=3}}`) were previously rendered as a single flat table due to an
internal JS conversion (`toJS`). They now render as a list, with record
elements shown as nested tables - which more accurately reflects their
Lua structure. This is the only divergence from the original
presentation.

To restore the old tabular layout, wrap all elements as records with
a consistent key:

```lua
-- Before (was a flat table, now a list with nested table):
${{1, 2, 3, {a=3}}}

-- After (explicit records, renders as a table):
${{{value=1}, {value=2}, {value=3}, {a=3}}}
```

Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
2026-03-09 11:45:04 +01:00
Zef Hemel a5c9227499 deno fmt 2026-03-08 16:11:29 +01:00
Zef Hemel bbcd9ac6aa Introduce new noFloatingPromises lint rule and fix violiations 2026-03-08 15:49:45 +01:00
Zef Hemel dbf275d75b Introduce biome as linter with lint fixes 2026-03-06 08:05:13 +01:00
Zef Hemel 803c5c478d Merge remote-tracking branch 'origin/main' into to-node 2026-02-27 15:05:49 +01:00
Oliver Marriott ea590f8e27 Formatter 2026-02-26 14:27:25 +11:00