@aionbuilders/nabu 0.1.0-alpha.9 → 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -9
- package/dist/behaviors/text/RichText.svelte +4 -1
- package/dist/behaviors/text/index.d.ts +2 -0
- package/dist/behaviors/text/index.js +2 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +2 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.js +54 -0
- package/dist/behaviors/text/rich-text.extension.js +47 -22
- package/dist/behaviors/text/text.behavior.svelte.d.ts +25 -1
- package/dist/behaviors/text/text.behavior.svelte.js +154 -18
- package/dist/behaviors/text/typography.extension.d.ts +6 -0
- package/dist/behaviors/text/typography.extension.js +24 -0
- package/dist/blocks/Block.svelte +5 -2
- package/dist/blocks/Nabu.svelte +22 -0
- package/dist/blocks/block.extension.js +10 -8
- package/dist/blocks/block.svelte.d.ts +24 -0
- package/dist/blocks/block.svelte.js +35 -0
- package/dist/blocks/blockquote/Blockquote.svelte +40 -0
- package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
- package/dist/blocks/blockquote/blockquote.extension.d.ts +1 -0
- package/dist/blocks/blockquote/blockquote.extension.js +71 -0
- package/dist/blocks/blockquote/blockquote.svelte.d.ts +55 -0
- package/dist/blocks/blockquote/blockquote.svelte.js +91 -0
- package/dist/blocks/blockquote/index.d.ts +3 -0
- package/dist/blocks/blockquote/index.js +3 -0
- package/dist/blocks/callout/Callout.svelte +69 -0
- package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
- package/dist/blocks/callout/callout.extension.d.ts +1 -0
- package/dist/blocks/callout/callout.extension.js +68 -0
- package/dist/blocks/callout/callout.svelte.d.ts +78 -0
- package/dist/blocks/callout/callout.svelte.js +184 -0
- package/dist/blocks/callout/index.d.ts +3 -0
- package/dist/blocks/callout/index.js +3 -0
- package/dist/blocks/code/Code.svelte +85 -0
- package/dist/blocks/code/Code.svelte.d.ts +11 -0
- package/dist/blocks/code/code.extension.d.ts +1 -0
- package/dist/blocks/code/code.extension.js +68 -0
- package/dist/blocks/code/code.svelte.d.ts +61 -0
- package/dist/blocks/code/code.svelte.js +221 -0
- package/dist/blocks/code/index.d.ts +3 -0
- package/dist/blocks/code/index.js +3 -0
- package/dist/blocks/dialogue/Dialogue.svelte +2 -0
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +3 -21
- package/dist/blocks/dialogue/dialogue.svelte.js +2 -50
- package/dist/blocks/divider/Divider.svelte +28 -0
- package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
- package/dist/blocks/divider/divider.extension.d.ts +1 -0
- package/dist/blocks/divider/divider.extension.js +87 -0
- package/dist/blocks/divider/divider.svelte.d.ts +49 -0
- package/dist/blocks/divider/divider.svelte.js +84 -0
- package/dist/blocks/divider/index.d.ts +3 -0
- package/dist/blocks/divider/index.js +3 -0
- package/dist/blocks/file/File.svelte +49 -0
- package/dist/blocks/file/File.svelte.d.ts +11 -0
- package/dist/blocks/file/file.extension.d.ts +1 -0
- package/dist/blocks/file/file.extension.js +19 -0
- package/dist/blocks/file/file.svelte.d.ts +29 -0
- package/dist/blocks/file/file.svelte.js +71 -0
- package/dist/blocks/file/index.d.ts +3 -0
- package/dist/blocks/file/index.js +3 -0
- package/dist/blocks/heading/Heading.svelte +3 -1
- package/dist/blocks/heading/heading.svelte.d.ts +4 -23
- package/dist/blocks/heading/heading.svelte.js +4 -47
- package/dist/blocks/image/Image.svelte +38 -0
- package/dist/blocks/image/Image.svelte.d.ts +11 -0
- package/dist/blocks/image/image.extension.d.ts +2 -0
- package/dist/blocks/image/image.extension.js +26 -0
- package/dist/blocks/image/image.svelte.d.ts +50 -0
- package/dist/blocks/image/image.svelte.js +92 -0
- package/dist/blocks/image/index.d.ts +3 -0
- package/dist/blocks/image/index.js +3 -0
- package/dist/blocks/index.d.ts +10 -0
- package/dist/blocks/index.js +10 -0
- package/dist/blocks/list/List.svelte +8 -2
- package/dist/blocks/list/ListItem.svelte +43 -7
- package/dist/blocks/list/hooks/onBeforeInput.hook.js +15 -2
- package/dist/blocks/list/index.d.ts +1 -0
- package/dist/blocks/list/index.js +1 -0
- package/dist/blocks/list/list-item.svelte.d.ts +14 -2
- package/dist/blocks/list/list-item.svelte.js +58 -7
- package/dist/blocks/list/list.behavior.svelte.d.ts +4 -4
- package/dist/blocks/list/list.behavior.svelte.js +5 -5
- package/dist/blocks/list/list.svelte.d.ts +13 -6
- package/dist/blocks/list/list.svelte.js +24 -6
- package/dist/blocks/list/todos.svelte.d.ts +35 -0
- package/dist/blocks/list/todos.svelte.js +76 -0
- package/dist/blocks/media/index.d.ts +2 -0
- package/dist/blocks/media/index.js +2 -0
- package/dist/blocks/media/media-block.svelte.d.ts +32 -0
- package/dist/blocks/media/media-block.svelte.js +69 -0
- package/dist/blocks/media/media.helpers.d.ts +19 -0
- package/dist/blocks/media/media.helpers.js +51 -0
- package/dist/blocks/megablock.svelte.js +1 -0
- package/dist/blocks/nabu.svelte.d.ts +94 -16
- package/dist/blocks/nabu.svelte.js +254 -3
- package/dist/blocks/paragraph/Paragraph.svelte +2 -0
- package/dist/blocks/paragraph/index.js +0 -3
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +3 -21
- package/dist/blocks/paragraph/paragraph.svelte.js +4 -53
- package/dist/blocks/selection.svelte.js +11 -1
- package/dist/blocks/text-block.svelte.d.ts +49 -0
- package/dist/blocks/text-block.svelte.js +74 -0
- package/dist/blocks/toggle/Toggle.svelte +84 -0
- package/dist/blocks/toggle/Toggle.svelte.d.ts +11 -0
- package/dist/blocks/toggle/index.d.ts +3 -0
- package/dist/blocks/toggle/index.js +3 -0
- package/dist/blocks/toggle/toggle.extension.d.ts +1 -0
- package/dist/blocks/toggle/toggle.extension.js +12 -0
- package/dist/blocks/toggle/toggle.svelte.d.ts +88 -0
- package/dist/blocks/toggle/toggle.svelte.js +252 -0
- package/dist/blocks/variable.svelte.d.ts +47 -0
- package/dist/blocks/variable.svelte.js +51 -0
- package/dist/blocks/video/Video.svelte +39 -0
- package/dist/blocks/video/Video.svelte.d.ts +11 -0
- package/dist/blocks/video/index.d.ts +3 -0
- package/dist/blocks/video/index.js +3 -0
- package/dist/blocks/video/video.extension.d.ts +1 -0
- package/dist/blocks/video/video.extension.js +19 -0
- package/dist/blocks/video/video.svelte.d.ts +28 -0
- package/dist/blocks/video/video.svelte.js +71 -0
- package/dist/blocks/zone/TemplateEditor.svelte +308 -0
- package/dist/blocks/zone/TemplateEditor.svelte.d.ts +11 -0
- package/dist/blocks/zone/Zone.svelte +158 -144
- package/dist/blocks/zone/ZoneEditor.svelte +289 -0
- package/dist/blocks/zone/ZoneEditor.svelte.d.ts +11 -0
- package/dist/blocks/zone/ZoneTemplatesList.svelte +188 -0
- package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +11 -0
- package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +3 -0
- package/dist/blocks/zone/hooks/onBeforeInput.hook.js +30 -0
- package/dist/blocks/zone/zone.extension.js +22 -6
- package/dist/blocks/zone/zone.svelte.d.ts +111 -2
- package/dist/blocks/zone/zone.svelte.js +304 -17
- package/dist/files/files.svelte.d.ts +61 -0
- package/dist/files/files.svelte.js +93 -0
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.js +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -2
- package/dist/nabu-theme.css +92 -0
- package/dist/overlays/context/Context.svelte +182 -0
- package/dist/overlays/context/Context.svelte.d.ts +17 -0
- package/dist/overlays/context/collect.d.ts +17 -0
- package/dist/overlays/context/collect.js +33 -0
- package/dist/overlays/context/context.extension.d.ts +2 -0
- package/dist/overlays/context/context.extension.js +8 -0
- package/dist/overlays/context/context.svelte.d.ts +82 -0
- package/dist/overlays/context/context.svelte.js +159 -0
- package/dist/overlays/context/index.d.ts +3 -0
- package/dist/overlays/context/index.js +3 -0
- package/dist/paste/html.paste.js +9 -1
- package/dist/presets.d.ts +3 -1
- package/dist/presets.js +21 -6
- package/dist/ui/DragHandle.svelte +141 -0
- package/dist/ui/DragHandle.svelte.d.ts +11 -0
- package/dist/ui/FloatingToolbar.svelte +117 -0
- package/dist/ui/FloatingToolbar.svelte.d.ts +17 -0
- package/dist/ui/SlashMenu.svelte +83 -0
- package/dist/ui/SlashMenu.svelte.d.ts +13 -0
- package/dist/ui/index.d.ts +4 -0
- package/dist/ui/index.js +4 -0
- package/dist/ui/slash-menu.svelte.d.ts +40 -0
- package/dist/ui/slash-menu.svelte.js +116 -0
- package/dist/utils/extensions.d.ts +54 -0
- package/dist/utils/extensions.js +40 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/placeholders.d.ts +10 -0
- package/dist/utils/placeholders.js +21 -0
- package/dist/vite.d.ts +16 -0
- package/dist/vite.js +23 -0
- package/package.json +10 -5
package/README.md
CHANGED
|
@@ -16,6 +16,25 @@ bun add @aionbuilders/nabu
|
|
|
16
16
|
|
|
17
17
|
Nabu depends on `loro-crdt`, which ships as a WebAssembly module. You must configure your Vite bundler to handle it.
|
|
18
18
|
|
|
19
|
+
The easiest way is the bundled plugin preset:
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// vite.config.js
|
|
23
|
+
import { defineConfig } from 'vite';
|
|
24
|
+
import { sveltekit } from '@sveltejs/kit/vite'; // or svelte()
|
|
25
|
+
import { nabu } from '@aionbuilders/nabu/vite';
|
|
26
|
+
|
|
27
|
+
export default defineConfig({
|
|
28
|
+
plugins: [
|
|
29
|
+
sveltekit(),
|
|
30
|
+
nabu() // registers vite-plugin-wasm + vite-plugin-top-level-await
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
<details>
|
|
36
|
+
<summary>Manual setup (equivalent)</summary>
|
|
37
|
+
|
|
19
38
|
**1. Install the required Vite plugins:**
|
|
20
39
|
|
|
21
40
|
```bash
|
|
@@ -39,6 +58,8 @@ export default defineConfig({
|
|
|
39
58
|
});
|
|
40
59
|
```
|
|
41
60
|
|
|
61
|
+
</details>
|
|
62
|
+
|
|
42
63
|
Without this setup, Nabu will fail to load.
|
|
43
64
|
|
|
44
65
|
## Basic Usage
|
|
@@ -136,19 +157,45 @@ All block types and behaviors are provided as extensions. Pass them to the `Nabu
|
|
|
136
157
|
|---|---|---|
|
|
137
158
|
| `ParagraphExtension` | `paragraph` block | — |
|
|
138
159
|
| `HeadingExtension` | `heading` block (h1–h6) | `# ` → h1, `## ` → h2, ... |
|
|
139
|
-
| `ListExtension` | `list` container (bullet/ordered) | — |
|
|
140
|
-
| `ListItemExtension` | `list-item` block | `Tab` indent, `Shift+Tab` unindent |
|
|
160
|
+
| `ListExtension` | `list` container (bullet/ordered/todo) | — |
|
|
161
|
+
| `ListItemExtension` | `list-item` block | `Tab` indent, `Shift+Tab` unindent; `[] ` or `[x] ` → to-do list |
|
|
141
162
|
| `DialogueExtension` | `dialogue` block | `-- ` → dialogue, `Backspace` at start → paragraph |
|
|
163
|
+
| `BlockquoteExtension` | `blockquote` block | `> ` → blockquote; `Backspace` at start (empty) → paragraph |
|
|
164
|
+
| `DividerExtension` | `divider` block (`<hr>`) | `--- ` → divider |
|
|
165
|
+
| `CodeExtension` | `code` block (monospace, multi-line) | ` ``` ` + Enter → code block; `Tab` inserts 2 spaces |
|
|
166
|
+
| `CalloutExtension` | `callout` block (note/tip/important/warning/caution) | `! ` → callout; click the icon to cycle variant |
|
|
167
|
+
| `ToggleExtension` | `toggle` block (collapsible) | created via slash menu |
|
|
168
|
+
| `ImageExtension` | `image` void media block | created via slash menu or `image:insert` / `image:pick` |
|
|
169
|
+
| `VideoExtension` | `video` void media block | created via slash menu or `video:insert` / `video:pick` |
|
|
170
|
+
| `FileExtension` | `file` void media block | created via slash menu or `file:insert` / `file:pick` |
|
|
142
171
|
| `RichTextExtension` | Inline marks (bold, italic...) | `Ctrl+B/I/U/E`, `Ctrl+Shift+X` |
|
|
172
|
+
| `TypographyExtension` | Smart typography substitutions | `--` + space → `—` |
|
|
173
|
+
| `MarkdownShortcutsExtension` | Inline markdown formatting while typing | see below |
|
|
143
174
|
|
|
144
175
|
### Typographic substitutions
|
|
145
176
|
|
|
146
|
-
|
|
177
|
+
Provided by `TypographyExtension` (included in TextPreset, DocumentPreset, and FullPreset). Nabu automatically applies substitutions as you type:
|
|
147
178
|
|
|
148
179
|
| Input | Output | Description |
|
|
149
180
|
|---|---|---|
|
|
150
181
|
| `--` + space | `— ` | Em-dash (French dialogue convention) |
|
|
151
182
|
|
|
183
|
+
### Inline markdown shortcuts
|
|
184
|
+
|
|
185
|
+
Provided by `MarkdownShortcutsExtension` (included in TextPreset, DocumentPreset, and FullPreset). Typing the closing delimiter applies the mark and strips the syntax characters:
|
|
186
|
+
|
|
187
|
+
| Type | Result |
|
|
188
|
+
|---|---|
|
|
189
|
+
| `**bold**` or `__bold__` | bold |
|
|
190
|
+
| `*italic*` or `_italic_` | italic |
|
|
191
|
+
| `` `code` `` | inline code |
|
|
192
|
+
| `~~strike~~` | strikethrough |
|
|
193
|
+
| `***bolditalic***` | bold + italic |
|
|
194
|
+
|
|
195
|
+
### Active formatting (stored marks)
|
|
196
|
+
|
|
197
|
+
Marks in Nabu are exact ranges — they never bleed into adjacent text. Pressing a mark shortcut (`Ctrl+B` / `Ctrl+I` / `Ctrl+U` / `Ctrl+E` / `Ctrl+Shift+X`) with a **collapsed cursor** starts that formatting for the next typed text. The mark persists as you type and clears automatically when you navigate away (arrow keys or click). With a **text selection**, the shortcut toggles the mark on the selection as usual.
|
|
198
|
+
|
|
152
199
|
## Programmatic API
|
|
153
200
|
|
|
154
201
|
```js
|
|
@@ -167,6 +214,147 @@ const markdown = engine.serialize('markdown');
|
|
|
167
214
|
// dialogue blocks serialize as: — Tu viens ce soir ?
|
|
168
215
|
|
|
169
216
|
const json = engine.serialize('json');
|
|
217
|
+
|
|
218
|
+
// Import — replaces the entire document
|
|
219
|
+
await engine.importMarkdown('# Title\n\nSome **bold** text.'); // requires MarkdownPasteExtension
|
|
220
|
+
await engine.importJSON(json); // loads a serialize('json') export
|
|
221
|
+
|
|
222
|
+
// Links
|
|
223
|
+
engine.exec('link:set', { href: 'https://example.com' }); // on the current selection
|
|
224
|
+
engine.exec('link:remove');
|
|
225
|
+
engine.exec('link:toggle', { href: 'https://example.com' });
|
|
226
|
+
|
|
227
|
+
// Other block actions
|
|
228
|
+
engine.exec('blockquote');
|
|
229
|
+
engine.exec('code');
|
|
230
|
+
engine.exec('callout');
|
|
231
|
+
engine.exec('toggle');
|
|
232
|
+
engine.exec('image:insert', { ref: 'https://example.com/image.jpg', alt: 'Description' });
|
|
233
|
+
engine.exec('image:pick'); // opens a file picker
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Usage with FloatingToolbar
|
|
237
|
+
|
|
238
|
+
A ready-made formatting toolbar that floats above the current selection:
|
|
239
|
+
|
|
240
|
+
```svelte
|
|
241
|
+
<script>
|
|
242
|
+
import { NabuEditor, FloatingToolbar, createDocumentEditor } from '@aionbuilders/nabu';
|
|
243
|
+
const engine = createDocumentEditor();
|
|
244
|
+
</script>
|
|
245
|
+
|
|
246
|
+
<FloatingToolbar {engine} />
|
|
247
|
+
<NabuEditor {engine} />
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
The toolbar is `position: fixed` and tracks the selection in viewport coordinates, so it can be dropped anywhere — no positioning wrapper needed. It toggles bold/italic/underline/code/strikethrough/link marks.
|
|
251
|
+
|
|
252
|
+
## Slash menu
|
|
253
|
+
|
|
254
|
+
An opt-in command palette, similar to `FloatingToolbar`. Type `/` in any block to open it, filter by typing, use `↑`/`↓` + `Enter` to select a command, and `Esc` to close.
|
|
255
|
+
|
|
256
|
+
```svelte
|
|
257
|
+
<script>
|
|
258
|
+
import { NabuEditor, SlashMenu, createFullEditor } from '@aionbuilders/nabu';
|
|
259
|
+
const engine = createFullEditor();
|
|
260
|
+
</script>
|
|
261
|
+
|
|
262
|
+
<SlashMenu {engine} />
|
|
263
|
+
<NabuEditor {engine} />
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Built-in commands cover: Text (paragraph), Headings 1–3, bulleted / numbered / to-do lists, Code, Callout, Quote, Toggle, Divider, Image, Video, and File.
|
|
267
|
+
|
|
268
|
+
Pass a `commands` prop to add or override entries:
|
|
269
|
+
|
|
270
|
+
```svelte
|
|
271
|
+
<SlashMenu {engine} commands={[...myCommands]} />
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Each command object has the shape `{ title, subtitle?, icon?, aliases?, run(engine) }`.
|
|
275
|
+
|
|
276
|
+
## Drag handles
|
|
277
|
+
|
|
278
|
+
An opt-in overlay for reordering blocks by dragging. On hover, a `⠿` grip appears to the left of the block under the pointer; drag it to move the block before or after any other block. Like `FloatingToolbar` / `SlashMenu`, it's a `position: fixed` island outside the editable area — drop it anywhere, no positioning wrapper needed.
|
|
279
|
+
|
|
280
|
+
```svelte
|
|
281
|
+
<script>
|
|
282
|
+
import { NabuEditor, DragHandle, createFullEditor } from '@aionbuilders/nabu';
|
|
283
|
+
const engine = createFullEditor();
|
|
284
|
+
</script>
|
|
285
|
+
|
|
286
|
+
<DragHandle {engine} />
|
|
287
|
+
<NabuEditor {engine} />
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Reordering goes through the Loro tree (`moveBefore` / `moveAfter`) and commits as a single transaction, so it's collaborative and undo-safe. Structural integrity is preserved automatically — e.g. dragging a list item out to the document root re-wraps it in its own list. A block can never be dropped into its own subtree.
|
|
291
|
+
|
|
292
|
+
## Files, images & media
|
|
293
|
+
|
|
294
|
+
Image, Video, and File are void (non-editable) media blocks. Insert them via the slash menu (`/image`, `/video`, `/file` — triggers a file picker) or programmatically:
|
|
295
|
+
|
|
296
|
+
```js
|
|
297
|
+
engine.exec('image:insert', { ref: 'https://cdn.example.com/photo.jpg', alt: 'Alt text' });
|
|
298
|
+
engine.exec('image:pick'); // opens a file picker
|
|
299
|
+
engine.exec('video:insert', { ref: 'https://cdn.example.com/clip.mp4' });
|
|
300
|
+
engine.exec('video:pick');
|
|
301
|
+
engine.exec('file:insert', { ref: 'https://cdn.example.com/doc.pdf' });
|
|
302
|
+
engine.exec('file:pick');
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Default (zero-config) mode
|
|
306
|
+
|
|
307
|
+
When a local file is added without any configuration, its bytes are stored **inside the Loro document** itself (in a separate `assets` map). The block stores a `nabu-asset:<id>` reference internally. This works offline and requires no backend — the document is completely self-contained.
|
|
308
|
+
|
|
309
|
+
Above a configurable size threshold (~2 MB by default), Nabu emits a warning: the CRDT is not designed to carry large binary assets.
|
|
310
|
+
|
|
311
|
+
### Production mode (your storage)
|
|
312
|
+
|
|
313
|
+
To keep binary data out of Loro and host assets on your own infrastructure, pass a `files` config to the `Nabu` constructor:
|
|
314
|
+
|
|
315
|
+
```js
|
|
316
|
+
import { createFullEditor } from '@aionbuilders/nabu';
|
|
317
|
+
|
|
318
|
+
const engine = createFullEditor({
|
|
319
|
+
files: {
|
|
320
|
+
// Called when a local file is added. Upload it and return a clean ref.
|
|
321
|
+
// Return nothing to fall back to the default (store bytes in Loro).
|
|
322
|
+
onBeforePersist: async (file, { signal, onProgress }) => {
|
|
323
|
+
const url = await uploadToYourCDN(file, { signal, onProgress });
|
|
324
|
+
return { ref: url };
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
// Turn a stored ref into a display URL.
|
|
328
|
+
// Default: identity for https:// URLs, native decoder for nabu-asset: refs.
|
|
329
|
+
// Override for private buckets or signed-URL storage.
|
|
330
|
+
resolve: (ref) => ref,
|
|
331
|
+
|
|
332
|
+
// Byte threshold before the default (Loro) mode warns. Default ~2 MB.
|
|
333
|
+
maxInlineSize: 2 * 1024 * 1024,
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
The `files` option is also accepted by the generic `createEditor({ preset, files })` and the bare `new Nabu({ extensions, files })` constructor.
|
|
339
|
+
|
|
340
|
+
## Task tracking (Todos)
|
|
341
|
+
|
|
342
|
+
To-do list blocks (`listType: 'todo'`) feed a reactive document-level registry. Use `Todos` to read and control them from outside the editor:
|
|
343
|
+
|
|
344
|
+
```js
|
|
345
|
+
import { Todos } from '@aionbuilders/nabu';
|
|
346
|
+
|
|
347
|
+
const todos = Todos.get(engine);
|
|
348
|
+
|
|
349
|
+
todos.count; // total number of to-do items
|
|
350
|
+
todos.doneCount; // number checked
|
|
351
|
+
todos.remaining; // number unchecked
|
|
352
|
+
todos.progress; // completion ratio, 0–1
|
|
353
|
+
todos.all; // all to-do items in document order
|
|
354
|
+
|
|
355
|
+
todos.checkAll();
|
|
356
|
+
todos.uncheckAll();
|
|
357
|
+
todos.goTo(item); // move the editor cursor to a specific to-do
|
|
170
358
|
```
|
|
171
359
|
|
|
172
360
|
## Architecture
|
|
@@ -190,11 +378,30 @@ Nabu uses `$state` and `$derived` throughout for fine-grained reactivity — onl
|
|
|
190
378
|
|
|
191
379
|
## Status
|
|
192
380
|
|
|
193
|
-
This is
|
|
194
|
-
|
|
195
|
-
- [
|
|
196
|
-
- [
|
|
197
|
-
- [
|
|
198
|
-
- [
|
|
381
|
+
This is a **beta release**. The core editing experience is functional, documented, and shipped:
|
|
382
|
+
|
|
383
|
+
- [x] Single ContentEditable architecture with Loro-CRDT
|
|
384
|
+
- [x] Structural editing (Enter/Backspace, split/merge, undo/redo)
|
|
385
|
+
- [x] Rich text marks (bold, italic, underline, code, strikethrough, link)
|
|
386
|
+
- [x] Active formatting — stored marks at a collapsed cursor
|
|
387
|
+
- [x] Inline markdown shortcuts (`**bold**`, `_italic_`, `` `code` ``, `~~strike~~`)
|
|
388
|
+
- [x] Persistence (IndexedDB auto-save via `createPersistedEditor`)
|
|
389
|
+
- [x] Floating toolbar UI (`FloatingToolbar` component)
|
|
390
|
+
- [x] Link support (`link:set` / `link:remove` / `link:toggle`)
|
|
391
|
+
- [x] Blockquote and Divider blocks
|
|
392
|
+
- [x] Code block (multi-line, monospace)
|
|
393
|
+
- [x] Callout block (note / tip / important / warning / caution variants)
|
|
394
|
+
- [x] Toggle block (collapsible)
|
|
395
|
+
- [x] To-do lists (`listType: 'todo'`) + `Todos` reactive registry
|
|
396
|
+
- [x] Image, Video, and File blocks with configurable upload system
|
|
397
|
+
- [x] Slash command menu (`SlashMenu` component)
|
|
398
|
+
- [x] Document import (`importMarkdown` / `importJSON`)
|
|
399
|
+
- [x] Placeholders and typography input rules
|
|
400
|
+
- [x] Drag-to-reorder handles (`DragHandle` component)
|
|
401
|
+
|
|
402
|
+
Post-beta roadmap:
|
|
403
|
+
|
|
404
|
+
- [ ] Embed blocks
|
|
405
|
+
- [ ] Block-selection primitive (click a drag handle to select the block as an object — insert-after / delete)
|
|
199
406
|
|
|
200
407
|
Contributions and feedback welcome.
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
19
|
{#each segments as op}
|
|
20
|
-
{#if op.attributes
|
|
20
|
+
{#if op.attributes?.link}
|
|
21
|
+
<a href={String(op.attributes.link)} class="nabu-link {getClasses(op.attributes)}" target="_blank" rel="noopener">{op.insert}</a>
|
|
22
|
+
{:else if op.attributes && Object.values(op.attributes).some(Boolean)}
|
|
21
23
|
<span class={getClasses(op.attributes)}>{op.insert}</span>
|
|
22
24
|
{:else}
|
|
23
25
|
{op.insert}
|
|
@@ -30,4 +32,5 @@
|
|
|
30
32
|
:global(.nabu-underline) { text-decoration: underline; }
|
|
31
33
|
:global(.nabu-strikethrough) { text-decoration: line-through; }
|
|
32
34
|
:global(.nabu-code) { font-family: monospace; background: rgba(135, 131, 120, 0.15); border-radius: 3px; padding: 0.1em 0.3em; }
|
|
35
|
+
:global(.nabu-link) { color: var(--nb-link, #4d9fff); text-decoration: underline; cursor: pointer; }
|
|
33
36
|
</style>
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export * from "./text.behavior.svelte.js";
|
|
2
2
|
export { RichTextExtension } from "./rich-text.extension.js";
|
|
3
|
+
export { TypographyExtension } from "./typography.extension.js";
|
|
4
|
+
export { MarkdownShortcutsExtension } from "./markdown-shortcuts.extension.js";
|
|
3
5
|
export { default as RichText } from "./RichText.svelte";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export * from './text.behavior.svelte.js';
|
|
2
2
|
export { RichTextExtension } from './rich-text.extension.js';
|
|
3
|
+
export { TypographyExtension } from './typography.extension.js';
|
|
4
|
+
export { MarkdownShortcutsExtension } from './markdown-shortcuts.extension.js';
|
|
3
5
|
export { default as RichText } from './RichText.svelte';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Extension } from '../../utils/extensions.js';
|
|
2
|
+
import { TextBehavior } from './text.behavior.svelte.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Build an inputRule that, when `closeChar` is typed and `pattern` matches the
|
|
6
|
+
* text before the cursor, strips the markdown delimiters and applies mark(s)
|
|
7
|
+
* to the inner content. `pattern` MUST capture the bare content in group 1, and
|
|
8
|
+
* match[0] MUST be exactly the delimiters+content to delete (no extra chars).
|
|
9
|
+
* @param {RegExp} pattern
|
|
10
|
+
* @param {string} closeChar the closing delimiter character being typed
|
|
11
|
+
* @param {string | string[]} marks mark name(s) to apply
|
|
12
|
+
* @returns {import('../../utils/extensions.js').InputRule}
|
|
13
|
+
*/
|
|
14
|
+
function markRule(pattern, closeChar, marks) {
|
|
15
|
+
const names = Array.isArray(marks) ? marks : [marks];
|
|
16
|
+
return {
|
|
17
|
+
pattern,
|
|
18
|
+
handler(nabu, block, match, sel) {
|
|
19
|
+
if (sel.data !== closeChar) return;
|
|
20
|
+
const behavior = block.behaviors.get('text');
|
|
21
|
+
if (!(behavior instanceof TextBehavior)) return;
|
|
22
|
+
const full = match[0]; // delimiters + content present before the cursor
|
|
23
|
+
const inner = match[1]; // bare content
|
|
24
|
+
if (!inner) return;
|
|
25
|
+
const start = sel.from - full.length;
|
|
26
|
+
behavior.delete({ index: start, length: full.length });
|
|
27
|
+
behavior.insert(start, inner);
|
|
28
|
+
for (const name of names) {
|
|
29
|
+
behavior.applyMark(name, true, { from: start, to: start + inner.length, isCollapsed: false });
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const MarkdownShortcutsExtension = new Extension('markdown-shortcuts', {
|
|
37
|
+
// ORDER MATTERS: most-specific (longest) delimiters first.
|
|
38
|
+
inputRules: [
|
|
39
|
+
// ***bold-italic*** (asterisks) — typed final '*' after '***x**'
|
|
40
|
+
markRule(/\*\*\*([^*]+)\*\*$/, '*', ['bold', 'italic']),
|
|
41
|
+
// **bold** — typed final '*' after '**x*'
|
|
42
|
+
markRule(/\*\*([^*]+)\*$/, '*', 'bold'),
|
|
43
|
+
// *italic* — typed final '*' after '*x' (not preceded by '*')
|
|
44
|
+
markRule(/(?<!\*)\*([^*]+)$/, '*', 'italic'),
|
|
45
|
+
// __bold__ — typed final '_' after '__x_'
|
|
46
|
+
markRule(/__([^_]+)_$/, '_', 'bold'),
|
|
47
|
+
// _italic_ — typed final '_' after '_x' (not preceded by '_')
|
|
48
|
+
markRule(/(?<!_)_([^_]+)$/, '_', 'italic'),
|
|
49
|
+
// `code` — typed final '`' after '`x'
|
|
50
|
+
markRule(/`([^`]+)$/, '`', 'code'),
|
|
51
|
+
// ~~strike~~ — typed final '~' after '~~x~'
|
|
52
|
+
markRule(/~~([^~]+)~$/, '~', 'strikethrough'),
|
|
53
|
+
],
|
|
54
|
+
});
|
|
@@ -22,6 +22,7 @@ function collectMarkTargets(nabu) {
|
|
|
22
22
|
const targets = [];
|
|
23
23
|
for (const [, block] of nabu.blocks) {
|
|
24
24
|
if (!block.selected) continue;
|
|
25
|
+
if (block.marksEnabled === false) continue;
|
|
25
26
|
const behavior = block.behaviors?.get('text');
|
|
26
27
|
if (!(behavior instanceof TextBehavior)) continue;
|
|
27
28
|
const sel = behavior.selection;
|
|
@@ -36,25 +37,30 @@ function collectMarkTargets(nabu) {
|
|
|
36
37
|
* @param {Nabu} nabu
|
|
37
38
|
* @param {string} markName
|
|
38
39
|
*/
|
|
39
|
-
function toggleMark(nabu, markName) {
|
|
40
|
+
async function toggleMark(nabu, markName) {
|
|
40
41
|
const startBlock = nabu.selection.startBlock;
|
|
41
42
|
const endBlock = nabu.selection.endBlock;
|
|
42
43
|
const startFocusData = startBlock?.focus(null, true);
|
|
43
44
|
const endFocusData = endBlock?.focus(null, true);
|
|
44
45
|
|
|
45
46
|
const targets = collectMarkTargets(nabu);
|
|
46
|
-
if (!targets.length)
|
|
47
|
+
if (!targets.length) {
|
|
48
|
+
// Collapsed cursor: toggle the pending stored mark for the next typed char.
|
|
49
|
+
if (nabu.selection.anchorBlock?.behaviors?.has('text')) nabu.toggleStoredMark(markName);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
47
52
|
|
|
48
53
|
const isFullyActive = targets.every(({ behavior, sel }) => behavior.isMarkActive(markName, sel));
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
await nabu.transact(() => {
|
|
55
|
+
for (const { behavior, sel } of targets) {
|
|
56
|
+
if (isFullyActive) {
|
|
57
|
+
behavior.removeMark(markName, sel);
|
|
58
|
+
} else {
|
|
59
|
+
behavior.applyMark(markName, true, sel);
|
|
60
|
+
}
|
|
54
61
|
}
|
|
55
|
-
}
|
|
62
|
+
});
|
|
56
63
|
|
|
57
|
-
nabu.commit();
|
|
58
64
|
if (startBlock && endBlock) {
|
|
59
65
|
nabu.focus({
|
|
60
66
|
from: { block: startBlock, offset: startFocusData?.start?.offset ?? 0 },
|
|
@@ -73,10 +79,11 @@ function toggleMark(nabu, markName) {
|
|
|
73
79
|
function applyMark(nabu, markName, value = true) {
|
|
74
80
|
const targets = collectMarkTargets(nabu);
|
|
75
81
|
if (!targets.length) return;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
return nabu.transact(() => {
|
|
83
|
+
for (const { behavior, sel } of targets) {
|
|
84
|
+
behavior.applyMark(markName, value, sel);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
/**
|
|
@@ -87,10 +94,11 @@ function applyMark(nabu, markName, value = true) {
|
|
|
87
94
|
function removeMark(nabu, markName) {
|
|
88
95
|
const targets = collectMarkTargets(nabu);
|
|
89
96
|
if (!targets.length) return;
|
|
90
|
-
|
|
91
|
-
behavior
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
return nabu.transact(() => {
|
|
98
|
+
for (const { behavior, sel } of targets) {
|
|
99
|
+
behavior.removeMark(markName, sel);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
/**
|
|
@@ -117,19 +125,36 @@ function onKeyDown(nabu, event) {
|
|
|
117
125
|
|
|
118
126
|
export const RichTextExtension = new Extension('rich-text', {
|
|
119
127
|
// Declare all mark attributes so Loro's applyDelta can handle them correctly.
|
|
120
|
-
//
|
|
128
|
+
// Marks are exact (expand: 'none') — they don't auto-extend at boundaries.
|
|
129
|
+
// Continuation of formatting when typing inside a marked span is handled by
|
|
130
|
+
// stored marks (nabu.storedMarks) toggled via Ctrl+B/I/etc. at a collapsed cursor.
|
|
121
131
|
loroTextStyles: {
|
|
122
|
-
bold: { expand: '
|
|
123
|
-
italic: { expand: '
|
|
124
|
-
underline: { expand: '
|
|
132
|
+
bold: { expand: 'none' },
|
|
133
|
+
italic: { expand: 'none' },
|
|
134
|
+
underline: { expand: 'none' },
|
|
125
135
|
code: { expand: 'none' }, // code spans don't expand on insert
|
|
126
|
-
strikethrough: { expand: '
|
|
136
|
+
strikethrough: { expand: 'none' },
|
|
137
|
+
link: { expand: 'none' }, // les liens ne s'étendent pas en tapant
|
|
127
138
|
},
|
|
128
139
|
actions: {
|
|
129
140
|
// Full API
|
|
130
141
|
'mark:toggle': (nabu, data) => toggleMark(nabu, data?.mark),
|
|
131
142
|
'mark:apply': (nabu, data) => applyMark(nabu, data?.mark, data?.value),
|
|
132
143
|
'mark:remove': (nabu, data) => removeMark(nabu, data?.mark),
|
|
144
|
+
// Links — the 'link' mark stores the href as its value
|
|
145
|
+
'link:set': (nabu, data) => {
|
|
146
|
+
if (!data?.href) return;
|
|
147
|
+
return applyMark(nabu, 'link', data.href);
|
|
148
|
+
},
|
|
149
|
+
'link:remove': (nabu) => removeMark(nabu, 'link'),
|
|
150
|
+
'link:toggle': (nabu, data) => {
|
|
151
|
+
const targets = collectMarkTargets(nabu);
|
|
152
|
+
if (!targets.length) return;
|
|
153
|
+
const allHaveLink = targets.every(({ behavior, sel }) => behavior.isMarkActive('link', sel));
|
|
154
|
+
if (allHaveLink) return removeMark(nabu, 'link');
|
|
155
|
+
if (!data?.href) return;
|
|
156
|
+
return applyMark(nabu, 'link', data.href);
|
|
157
|
+
},
|
|
133
158
|
// Aliases
|
|
134
159
|
'bold': (nabu) => toggleMark(nabu, 'bold'),
|
|
135
160
|
'italic': (nabu) => toggleMark(nabu, 'italic'),
|
|
@@ -30,6 +30,11 @@ export class TextBehavior {
|
|
|
30
30
|
direction: "forward" | "backward" | "none";
|
|
31
31
|
} | null;
|
|
32
32
|
positions: number;
|
|
33
|
+
/**
|
|
34
|
+
* Number of whitespace-separated words in this text.
|
|
35
|
+
* @returns {number}
|
|
36
|
+
*/
|
|
37
|
+
get wordCount(): number;
|
|
33
38
|
/**
|
|
34
39
|
* @param {HTMLElement} element
|
|
35
40
|
* @param {NabuSelection} globalSelection
|
|
@@ -50,13 +55,32 @@ export class TextBehavior {
|
|
|
50
55
|
/** @param {InputEvent} event @param {ReturnType<TextBehavior["getSelection"]>} [selection] */
|
|
51
56
|
handleBeforeInput(event: InputEvent, selection?: ReturnType<TextBehavior["getSelection"]>): any;
|
|
52
57
|
/** @param {InputEvent} event @param {ReturnType<TextBehavior["getSelection"]>} [selection] */
|
|
53
|
-
handleInsertText(event: InputEvent, selection?: ReturnType<TextBehavior["getSelection"]>):
|
|
58
|
+
handleInsertText(event: InputEvent, selection?: ReturnType<TextBehavior["getSelection"]>): true | undefined;
|
|
54
59
|
/** @param {InputEvent} event @param {ReturnType<TextBehavior["getSelection"]>} [sel] */
|
|
55
60
|
handleInsertLineBreak(event: InputEvent, sel?: ReturnType<TextBehavior["getSelection"]>): void;
|
|
56
61
|
/** @param {InputEvent} event @param {ReturnType<TextBehavior["getSelection"]>} [sel] */
|
|
57
62
|
handleDeleteContentBackward(event: InputEvent, sel?: ReturnType<TextBehavior["getSelection"]>): void;
|
|
58
63
|
/** @param {InputEvent} event @param {ReturnType<TextBehavior["getSelection"]>} [sel] */
|
|
59
64
|
handleDeleteContentForward(event: InputEvent, sel?: ReturnType<TextBehavior["getSelection"]>): void;
|
|
65
|
+
/**
|
|
66
|
+
* Deletes the word before the cursor (Ctrl+Backspace on Win/Linux,
|
|
67
|
+
* Option+Delete on Mac), including the whitespace that precedes it
|
|
68
|
+
* so no orphan space is left behind (issue #4).
|
|
69
|
+
* @param {InputEvent} event @param {ReturnType<TextBehavior["getSelection"]>} [sel]
|
|
70
|
+
*/
|
|
71
|
+
handleDeleteWordBackward(event: InputEvent, sel?: ReturnType<TextBehavior["getSelection"]>): true | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Deletes the word after the cursor (Ctrl+Delete / Option+Fn+Delete),
|
|
74
|
+
* including its trailing whitespace/punctuation.
|
|
75
|
+
* @param {InputEvent} event @param {ReturnType<TextBehavior["getSelection"]>} [sel]
|
|
76
|
+
*/
|
|
77
|
+
handleDeleteWordForward(event: InputEvent, sel?: ReturnType<TextBehavior["getSelection"]>): true | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Deletes from the start of the current soft line to the cursor
|
|
80
|
+
* (Cmd+Backspace on Mac).
|
|
81
|
+
* @param {InputEvent} event @param {ReturnType<TextBehavior["getSelection"]>} [sel]
|
|
82
|
+
*/
|
|
83
|
+
handleDeleteSoftLineBackward(event: InputEvent, sel?: ReturnType<TextBehavior["getSelection"]>): true | undefined;
|
|
60
84
|
/** @param {InputEvent} event @param {ReturnType<TextBehavior["getSelection"]>} [sel] */
|
|
61
85
|
handleInsertParagraph(event: InputEvent, sel?: ReturnType<TextBehavior["getSelection"]>): any;
|
|
62
86
|
/**
|