@aionbuilders/nabu 0.1.0-beta.0 → 0.1.1
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/CHANGELOG.md +531 -0
- package/LICENSE +21 -0
- package/README.md +72 -341
- package/dist/behaviors/text/RichText.svelte +24 -4
- package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +3 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.js +35 -10
- package/dist/behaviors/text/markdown-syntax.d.ts +42 -0
- package/dist/behaviors/text/markdown-syntax.js +81 -0
- package/dist/behaviors/text/rich-text.extension.d.ts +3 -0
- package/dist/behaviors/text/rich-text.extension.js +95 -38
- package/dist/behaviors/text/text.behavior.svelte.d.ts +195 -55
- package/dist/behaviors/text/text.behavior.svelte.js +531 -103
- package/dist/behaviors/text/typography.extension.d.ts +2 -1
- package/dist/behaviors/text/typography.extension.js +3 -2
- package/dist/blocks/BlockList.svelte +48 -0
- package/dist/blocks/BlockList.svelte.d.ts +17 -0
- package/dist/blocks/Nabu.svelte +169 -25
- package/dist/blocks/Nabu.svelte.d.ts +13 -0
- package/dist/blocks/block.extension.d.ts +3 -0
- package/dist/blocks/block.extension.js +4 -7
- package/dist/blocks/block.svelte.d.ts +350 -86
- package/dist/blocks/block.svelte.js +370 -59
- package/dist/blocks/blockquote/Blockquote.svelte +1 -2
- package/dist/blocks/blockquote/blockquote.extension.d.ts +4 -1
- package/dist/blocks/blockquote/blockquote.extension.js +14 -5
- package/dist/blocks/blockquote/blockquote.svelte.d.ts +19 -11
- package/dist/blocks/blockquote/blockquote.svelte.js +58 -13
- package/dist/blocks/callout/Callout.svelte +6 -8
- package/dist/blocks/callout/callout.extension.d.ts +4 -1
- package/dist/blocks/callout/callout.extension.js +19 -3
- package/dist/blocks/callout/callout.svelte.d.ts +5 -3
- package/dist/blocks/callout/callout.svelte.js +11 -6
- package/dist/blocks/chunks.d.ts +49 -0
- package/dist/blocks/chunks.js +90 -0
- package/dist/blocks/code/Code.svelte +7 -8
- package/dist/blocks/code/code.extension.d.ts +4 -1
- package/dist/blocks/code/code.extension.js +22 -2
- package/dist/blocks/code/code.svelte.d.ts +9 -2
- package/dist/blocks/code/code.svelte.js +49 -25
- package/dist/blocks/container.utils.d.ts +85 -13
- package/dist/blocks/container.utils.js +338 -178
- package/dist/blocks/dialogue/Dialogue.svelte +8 -4
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +33 -2
- package/dist/blocks/dialogue/dialogue.svelte.js +58 -4
- package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +2 -2
- package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +6 -4
- package/dist/blocks/dialogue/index.d.ts +12 -1
- package/dist/blocks/dialogue/index.js +51 -35
- package/dist/blocks/divider/divider.extension.d.ts +23 -1
- package/dist/blocks/divider/divider.extension.js +85 -19
- package/dist/blocks/divider/divider.svelte.d.ts +7 -2
- package/dist/blocks/divider/divider.svelte.js +9 -4
- package/dist/blocks/file/File.svelte +13 -6
- package/dist/blocks/file/file.extension.d.ts +4 -1
- package/dist/blocks/file/file.extension.js +9 -1
- package/dist/blocks/file/file.svelte.d.ts +3 -3
- package/dist/blocks/file/file.svelte.js +20 -14
- package/dist/blocks/heading/Heading.svelte +1 -2
- package/dist/blocks/heading/heading.svelte.d.ts +23 -11
- package/dist/blocks/heading/heading.svelte.js +68 -13
- package/dist/blocks/heading/hooks/onBeforeInput.hook.js +7 -5
- package/dist/blocks/heading/index.d.ts +2 -2
- package/dist/blocks/heading/index.js +33 -8
- package/dist/blocks/image/Image.svelte +5 -2
- package/dist/blocks/image/image.extension.d.ts +4 -1
- package/dist/blocks/image/image.extension.js +9 -1
- package/dist/blocks/image/image.svelte.d.ts +17 -6
- package/dist/blocks/image/image.svelte.js +33 -11
- package/dist/blocks/index.d.ts +1 -1
- package/dist/blocks/index.js +1 -1
- package/dist/blocks/list/List.svelte +1 -0
- package/dist/blocks/list/ListItem.svelte +1 -0
- package/dist/blocks/list/convert.d.ts +20 -0
- package/dist/blocks/list/convert.js +92 -0
- package/dist/blocks/list/hooks/onBeforeInput.hook.js +49 -28
- package/dist/blocks/list/html-flat.d.ts +78 -0
- package/dist/blocks/list/html-flat.js +244 -0
- package/dist/blocks/list/indent.d.ts +86 -0
- package/dist/blocks/list/indent.js +205 -0
- package/dist/blocks/list/index.d.ts +6 -3
- package/dist/blocks/list/index.js +42 -31
- package/dist/blocks/list/list-item.svelte.d.ts +32 -18
- package/dist/blocks/list/list-item.svelte.js +99 -100
- package/dist/blocks/list/list.behavior.svelte.d.ts +4 -1
- package/dist/blocks/list/list.behavior.svelte.js +6 -1
- package/dist/blocks/list/list.svelte.d.ts +89 -18
- package/dist/blocks/list/list.svelte.js +129 -125
- package/dist/blocks/list/markdown.d.ts +149 -0
- package/dist/blocks/list/markdown.js +442 -0
- package/dist/blocks/list/normalize.d.ts +11 -0
- package/dist/blocks/list/normalize.js +396 -0
- package/dist/blocks/list/paste.d.ts +45 -0
- package/dist/blocks/list/paste.js +242 -0
- package/dist/blocks/list/step-back.d.ts +24 -0
- package/dist/blocks/list/step-back.js +87 -0
- package/dist/blocks/list/to-list.d.ts +7 -0
- package/dist/blocks/list/to-list.js +44 -0
- package/dist/blocks/list/todos-toggle.d.ts +20 -0
- package/dist/blocks/list/todos-toggle.js +48 -0
- package/dist/blocks/media/markdown.d.ts +12 -0
- package/dist/blocks/media/markdown.js +26 -0
- package/dist/blocks/media/media-block.svelte.d.ts +77 -2
- package/dist/blocks/media/media-block.svelte.js +124 -12
- package/dist/blocks/media/media.helpers.d.ts +6 -1
- package/dist/blocks/media/media.helpers.js +43 -6
- package/dist/blocks/megablock.svelte.d.ts +50 -19
- package/dist/blocks/megablock.svelte.js +114 -74
- package/dist/blocks/move.d.ts +23 -0
- package/dist/blocks/move.js +92 -0
- package/dist/blocks/nabu.svelte.d.ts +764 -71
- package/dist/blocks/nabu.svelte.js +1753 -189
- package/dist/blocks/paragraph/Paragraph.svelte +1 -2
- package/dist/blocks/paragraph/index.d.ts +2 -2
- package/dist/blocks/paragraph/index.js +35 -13
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +46 -14
- package/dist/blocks/paragraph/paragraph.svelte.js +77 -16
- package/dist/blocks/paragraph/table.html.d.ts +9 -0
- package/dist/blocks/paragraph/table.html.js +111 -0
- package/dist/blocks/paragraph/table.markdown.d.ts +32 -0
- package/dist/blocks/paragraph/table.markdown.js +90 -0
- package/dist/blocks/region/Region.svelte +264 -0
- package/dist/blocks/region/Region.svelte.d.ts +11 -0
- package/dist/blocks/region/actions.d.ts +135 -0
- package/dist/blocks/region/actions.js +402 -0
- package/dist/blocks/region/close.d.ts +35 -0
- package/dist/blocks/region/close.js +130 -0
- package/dist/blocks/region/commands.d.ts +6 -0
- package/dist/blocks/region/commands.js +277 -0
- package/dist/blocks/region/create.d.ts +72 -0
- package/dist/blocks/region/create.js +208 -0
- package/dist/blocks/region/end-marker.d.ts +35 -0
- package/dist/blocks/region/end-marker.js +51 -0
- package/dist/blocks/region/facts.d.ts +69 -0
- package/dist/blocks/region/facts.js +152 -0
- package/dist/blocks/region/format.d.ts +91 -0
- package/dist/blocks/region/format.js +260 -0
- package/dist/blocks/region/index.d.ts +14 -0
- package/dist/blocks/region/index.js +14 -0
- package/dist/blocks/region/insert.d.ts +59 -0
- package/dist/blocks/region/insert.js +102 -0
- package/dist/blocks/region/messages.d.ts +254 -0
- package/dist/blocks/region/messages.js +131 -0
- package/dist/blocks/region/normalize.d.ts +7 -0
- package/dist/blocks/region/normalize.js +170 -0
- package/dist/blocks/region/region.extension.d.ts +58 -0
- package/dist/blocks/region/region.extension.js +119 -0
- package/dist/blocks/region/region.svelte.d.ts +221 -0
- package/dist/blocks/region/region.svelte.js +582 -0
- package/dist/blocks/region/regions.svelte.d.ts +141 -0
- package/dist/blocks/region/regions.svelte.js +276 -0
- package/dist/blocks/region/serialize.d.ts +57 -0
- package/dist/blocks/region/serialize.js +112 -0
- package/dist/blocks/region/types.d.ts +255 -0
- package/dist/blocks/region/types.js +204 -0
- package/dist/blocks/selection.svelte.d.ts +106 -8
- package/dist/blocks/selection.svelte.js +622 -74
- package/dist/blocks/subthread.d.ts +80 -0
- package/dist/blocks/subthread.js +167 -0
- package/dist/blocks/text-block.svelte.d.ts +35 -14
- package/dist/blocks/text-block.svelte.js +42 -8
- package/dist/blocks/toggle/Toggle.svelte +4 -15
- package/dist/blocks/toggle/markdown.d.ts +20 -0
- package/dist/blocks/toggle/markdown.js +112 -0
- package/dist/blocks/toggle/toggle.extension.d.ts +4 -1
- package/dist/blocks/toggle/toggle.extension.js +6 -0
- package/dist/blocks/toggle/toggle.svelte.d.ts +55 -8
- package/dist/blocks/toggle/toggle.svelte.js +134 -34
- package/dist/blocks/undo-selection.d.ts +175 -0
- package/dist/blocks/undo-selection.js +360 -0
- package/dist/blocks/video/Video.svelte +5 -2
- package/dist/blocks/video/video.extension.d.ts +4 -1
- package/dist/blocks/video/video.extension.js +9 -1
- package/dist/blocks/video/video.svelte.d.ts +6 -5
- package/dist/blocks/video/video.svelte.js +18 -9
- package/dist/extend.d.ts +55 -0
- package/dist/extend.js +88 -0
- package/dist/files/assets.clipboard.d.ts +77 -0
- package/dist/files/assets.clipboard.js +152 -0
- package/dist/files/files.svelte.d.ts +321 -19
- package/dist/files/files.svelte.js +847 -43
- package/dist/files/index.d.ts +3 -1
- package/dist/files/index.js +3 -1
- package/dist/files/outbox.d.ts +69 -0
- package/dist/files/outbox.js +48 -0
- package/dist/files/status.d.ts +65 -0
- package/dist/files/status.js +87 -0
- package/dist/files/store.d.ts +97 -0
- package/dist/files/store.js +65 -0
- package/dist/files/uploads.svelte.d.ts +174 -0
- package/dist/files/uploads.svelte.js +504 -0
- package/dist/index.d.ts +68 -9
- package/dist/index.js +117 -10
- package/dist/nabu-theme.css +21 -1
- package/dist/paste/html.paste.d.ts +74 -3
- package/dist/paste/html.paste.js +550 -86
- package/dist/paste/markdown-inline.d.ts +86 -0
- package/dist/paste/markdown-inline.js +528 -0
- package/dist/paste/markdown.paste.d.ts +2 -8
- package/dist/paste/markdown.paste.js +78 -94
- package/dist/paste/nabu.paste.d.ts +3 -0
- package/dist/paste/nabu.paste.js +29 -3
- package/dist/paste/plain-text.paste.d.ts +2 -2
- package/dist/paste/plain-text.paste.js +3 -3
- package/dist/persistence/asset-store.d.ts +51 -0
- package/dist/persistence/asset-store.js +103 -0
- package/dist/persistence/autosave.d.ts +53 -0
- package/dist/persistence/autosave.js +62 -0
- package/dist/persistence/compact.d.ts +162 -0
- package/dist/persistence/compact.js +141 -0
- package/dist/persistence/history.d.ts +77 -0
- package/dist/persistence/history.js +176 -0
- package/dist/persistence/indexeddb.d.ts +190 -4
- package/dist/persistence/indexeddb.js +333 -29
- package/dist/persistence/merge.d.ts +38 -0
- package/dist/persistence/merge.js +36 -0
- package/dist/persistence/outbox.d.ts +25 -0
- package/dist/persistence/outbox.js +40 -0
- package/dist/persistence/persistence.d.ts +70 -9
- package/dist/persistence/persistence.js +507 -35
- package/dist/persistence/recovery.d.ts +79 -0
- package/dist/persistence/recovery.js +79 -0
- package/dist/persistence/release.d.ts +34 -0
- package/dist/persistence/release.js +64 -0
- package/dist/persistence/state.svelte.d.ts +53 -0
- package/dist/persistence/state.svelte.js +48 -0
- package/dist/persistence/sync.d.ts +39 -0
- package/dist/persistence/sync.js +138 -0
- package/dist/persistence/tail.d.ts +42 -0
- package/dist/persistence/tail.js +103 -0
- package/dist/presets.d.ts +29 -26
- package/dist/presets.js +35 -13
- package/dist/themes/atelier.css +318 -0
- package/dist/ui/CommandChooser.svelte +153 -0
- package/dist/ui/CommandChooser.svelte.d.ts +13 -0
- package/dist/ui/CommandInvite.svelte +99 -0
- package/dist/ui/CommandInvite.svelte.d.ts +12 -0
- package/dist/ui/DragHandle.svelte +97 -21
- package/dist/ui/FloatingToolbar.svelte +75 -27
- package/dist/ui/FloatingToolbar.svelte.d.ts +10 -0
- package/dist/ui/SlashMenu.svelte +147 -15
- package/dist/ui/SlashMenu.svelte.d.ts +20 -0
- package/dist/ui/anchor.d.ts +112 -0
- package/dist/ui/anchor.js +136 -0
- package/dist/ui/index.d.ts +7 -1
- package/dist/ui/index.js +12 -1
- package/dist/ui/slash-menu.svelte.d.ts +79 -7
- package/dist/ui/slash-menu.svelte.js +85 -51
- package/dist/utils/command-confirm.svelte.d.ts +349 -0
- package/dist/utils/command-confirm.svelte.js +673 -0
- package/dist/utils/commands.d.ts +328 -0
- package/dist/utils/commands.js +416 -0
- package/dist/utils/composition.d.ts +28 -0
- package/dist/utils/composition.js +51 -0
- package/dist/utils/dom-scope.d.ts +14 -0
- package/dist/utils/dom-scope.js +20 -0
- package/dist/utils/drop.d.ts +160 -0
- package/dist/utils/drop.js +305 -0
- package/dist/utils/extensions.d.ts +439 -45
- package/dist/utils/extensions.js +271 -29
- package/dist/utils/html.d.ts +44 -0
- package/dist/utils/html.js +183 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/keys.d.ts +120 -0
- package/dist/utils/keys.js +248 -0
- package/dist/utils/links.d.ts +22 -0
- package/dist/utils/links.js +34 -0
- package/dist/utils/placeholders.d.ts +81 -3
- package/dist/utils/placeholders.js +73 -3
- package/dist/utils/selection.svelte.d.ts +48 -20
- package/dist/utils/selection.svelte.js +60 -10
- package/dist/utils/spellcheck.d.ts +9 -0
- package/dist/utils/spellcheck.js +17 -0
- package/dist/utils/tab.d.ts +31 -0
- package/dist/utils/tab.js +117 -0
- package/dist/utils/words.d.ts +42 -0
- package/dist/utils/words.js +147 -0
- package/dist/vite.d.ts +9 -3
- package/dist/vite.js +19 -8
- package/package.json +56 -20
- package/dist/blocks/variable.svelte.d.ts +0 -47
- package/dist/blocks/variable.svelte.js +0 -51
- package/dist/blocks/zone/TemplateEditor.svelte +0 -308
- package/dist/blocks/zone/TemplateEditor.svelte.d.ts +0 -11
- package/dist/blocks/zone/Zone.svelte +0 -272
- package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
- package/dist/blocks/zone/ZoneEditor.svelte +0 -289
- package/dist/blocks/zone/ZoneEditor.svelte.d.ts +0 -11
- package/dist/blocks/zone/ZoneTemplatesList.svelte +0 -188
- package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +0 -11
- package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +0 -3
- package/dist/blocks/zone/hooks/onBeforeInput.hook.js +0 -30
- package/dist/blocks/zone/index.d.ts +0 -2
- package/dist/blocks/zone/index.js +0 -2
- package/dist/blocks/zone/zone.extension.d.ts +0 -2
- package/dist/blocks/zone/zone.extension.js +0 -237
- package/dist/blocks/zone/zone.svelte.d.ts +0 -221
- package/dist/blocks/zone/zone.svelte.js +0 -608
- package/dist/overlays/context/Context.svelte +0 -182
- package/dist/overlays/context/Context.svelte.d.ts +0 -17
- package/dist/overlays/context/collect.d.ts +0 -17
- package/dist/overlays/context/collect.js +0 -33
- package/dist/overlays/context/context.extension.d.ts +0 -2
- package/dist/overlays/context/context.extension.js +0 -8
- package/dist/overlays/context/context.svelte.d.ts +0 -82
- package/dist/overlays/context/context.svelte.js +0 -159
- package/dist/overlays/context/index.d.ts +0 -3
- package/dist/overlays/context/index.js +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Killian Di Vincenzo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
# Nabu
|
|
1
|
+
# Nabu
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Nabu is a modular, local-first block editor for **Svelte 5**. It combines the cross-block selection of document editors (Google Docs, ProseMirror) with the structural flexibility of block editors (Notion), on a single `contenteditable` and a CRDT core ([Loro](https://loro.dev)). You pick the blocks and behaviors you need from a list of extensions, from a `<textarea>` replacement to a full document editor, and save to the browser with one call.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Website, documentation and live demos: [nabu.aion.builders](https://nabu.aion.builders)**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
> **Status: public beta** (`0.1.0`). The editing core is complete and tested, but the API may still change before 1.0. Breaking changes are listed in the [changelog](https://nabu.aion.builders/changelog) ([CHANGELOG.md](CHANGELOG.md)). Known gaps (mobile keyboards, Firefox and Safari, tables, real-time collaboration between machines) are listed honestly on the [limits page](https://nabu.aion.builders/architecture/limits).
|
|
8
|
+
|
|
9
|
+
### Versioning (0.x)
|
|
10
|
+
|
|
11
|
+
- A `0.` version means the API can still change. 1.0.0 will mark the stability commitment.
|
|
12
|
+
- Breaking changes arrive only in a minor version (0.2.0, 0.3.0, ...), each with a migration note in the changelog.
|
|
13
|
+
- Patch versions (0.1.x) are fixes only: they keep the public API and the stable `@aionbuilders/nabu/extend` contract.
|
|
14
|
+
- `nabu.internals` is unstable and may change in any version.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
8
17
|
|
|
9
18
|
```bash
|
|
10
19
|
npm install @aionbuilders/nabu
|
|
@@ -12,11 +21,10 @@ npm install @aionbuilders/nabu
|
|
|
12
21
|
bun add @aionbuilders/nabu
|
|
13
22
|
```
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Nabu depends on `loro-crdt`, which ships as a WebAssembly module. You must configure your Vite bundler to handle it.
|
|
24
|
+
### Requirements
|
|
18
25
|
|
|
19
|
-
|
|
26
|
+
- **Svelte 5.20 or newer**.
|
|
27
|
+
- A Vite setup (SvelteKit, or Svelte + Vite) that can load WebAssembly. Loro ships as a WebAssembly module loaded with top-level `await`, so the build needs `vite-plugin-wasm` and `build.target: 'esnext'`. The bundled helper does both:
|
|
20
28
|
|
|
21
29
|
```js
|
|
22
30
|
// vite.config.js
|
|
@@ -25,383 +33,106 @@ import { sveltekit } from '@sveltejs/kit/vite'; // or svelte()
|
|
|
25
33
|
import { nabu } from '@aionbuilders/nabu/vite';
|
|
26
34
|
|
|
27
35
|
export default defineConfig({
|
|
28
|
-
plugins: [
|
|
29
|
-
sveltekit(),
|
|
30
|
-
nabu() // registers vite-plugin-wasm + vite-plugin-top-level-await
|
|
31
|
-
]
|
|
36
|
+
plugins: [sveltekit(), nabu()]
|
|
32
37
|
});
|
|
33
38
|
```
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
<summary>Manual setup (equivalent)</summary>
|
|
37
|
-
|
|
38
|
-
**1. Install the required Vite plugins:**
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
npm install -D vite-plugin-wasm vite-plugin-top-level-await
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
**2. Add them to your `vite.config.js`:**
|
|
40
|
+
Without this setup, Nabu fails to load. Why `esnext`, the manual equivalent and common errors: [Installation](https://nabu.aion.builders/docs/getting-started/installation).
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
import { defineConfig } from 'vite';
|
|
48
|
-
import { sveltekit } from '@sveltejs/kit/vite'; // or svelte()
|
|
49
|
-
import wasm from 'vite-plugin-wasm';
|
|
50
|
-
import topLevelAwait from 'vite-plugin-top-level-await';
|
|
51
|
-
|
|
52
|
-
export default defineConfig({
|
|
53
|
-
plugins: [
|
|
54
|
-
sveltekit(),
|
|
55
|
-
wasm(),
|
|
56
|
-
topLevelAwait()
|
|
57
|
-
]
|
|
58
|
-
});
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
</details>
|
|
62
|
-
|
|
63
|
-
Without this setup, Nabu will fail to load.
|
|
64
|
-
|
|
65
|
-
## Basic Usage
|
|
66
|
-
|
|
67
|
-
**With a preset (recommended):**
|
|
42
|
+
## Minimal example
|
|
68
43
|
|
|
69
44
|
```svelte
|
|
70
45
|
<script>
|
|
71
|
-
import { NabuEditor,
|
|
46
|
+
import { NabuEditor, createDocumentEditor } from '@aionbuilders/nabu';
|
|
72
47
|
|
|
73
|
-
const engine =
|
|
74
|
-
</script>
|
|
75
|
-
|
|
76
|
-
<NabuEditor {engine} />
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
**Manual setup:**
|
|
80
|
-
|
|
81
|
-
```svelte
|
|
82
|
-
<script>
|
|
83
|
-
import {
|
|
84
|
-
Nabu,
|
|
85
|
-
NabuEditor,
|
|
86
|
-
ParagraphExtension,
|
|
87
|
-
HeadingExtension,
|
|
88
|
-
ListExtension,
|
|
89
|
-
ListItemExtension,
|
|
90
|
-
DialogueExtension,
|
|
91
|
-
RichTextExtension
|
|
92
|
-
} from '@aionbuilders/nabu';
|
|
93
|
-
|
|
94
|
-
const engine = new Nabu({
|
|
95
|
-
extensions: [
|
|
96
|
-
ParagraphExtension,
|
|
97
|
-
HeadingExtension,
|
|
98
|
-
ListExtension,
|
|
99
|
-
ListItemExtension,
|
|
100
|
-
DialogueExtension,
|
|
101
|
-
RichTextExtension
|
|
102
|
-
]
|
|
103
|
-
});
|
|
48
|
+
const engine = createDocumentEditor();
|
|
104
49
|
</script>
|
|
105
50
|
|
|
106
51
|
<NabuEditor {engine} />
|
|
107
52
|
```
|
|
108
53
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Nabu ships with ready-to-use presets for common use cases.
|
|
112
|
-
|
|
113
|
-
### Preset arrays
|
|
114
|
-
|
|
115
|
-
Composable — spread and extend them with your own extensions:
|
|
116
|
-
|
|
117
|
-
```js
|
|
118
|
-
import { FullPreset, createEditor } from '@aionbuilders/nabu';
|
|
119
|
-
|
|
120
|
-
const engine = createEditor({
|
|
121
|
-
preset: FullPreset,
|
|
122
|
-
extensions: [MyCustomExtension]
|
|
123
|
-
});
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
| Preset | Includes |
|
|
127
|
-
|---|---|
|
|
128
|
-
| `MinimalPreset` | Paragraph only |
|
|
129
|
-
| `TextPreset` | Paragraph + rich text marks |
|
|
130
|
-
| `DocumentPreset` | Paragraph + Headings + rich text |
|
|
131
|
-
| `FullPreset` | All built-in blocks + rich text (including Dialogue) |
|
|
132
|
-
|
|
133
|
-
### Factory functions
|
|
134
|
-
|
|
135
|
-
One-liner shortcuts for the most common cases:
|
|
136
|
-
|
|
137
|
-
```js
|
|
138
|
-
import {
|
|
139
|
-
createMinimalEditor, // paragraph only — textarea replacement
|
|
140
|
-
createTextEditor, // paragraph + bold/italic/...
|
|
141
|
-
createDocumentEditor, // paragraph + headings + rich text
|
|
142
|
-
createFullEditor, // everything
|
|
143
|
-
createEditor // generic — takes any preset
|
|
144
|
-
} from '@aionbuilders/nabu';
|
|
145
|
-
|
|
146
|
-
const engine = createFullEditor();
|
|
147
|
-
|
|
148
|
-
// Add custom extensions on top of a preset
|
|
149
|
-
const engine = createTextEditor({ extensions: [MyExtension] });
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## Extensions
|
|
153
|
-
|
|
154
|
-
All block types and behaviors are provided as extensions. Pass them to the `Nabu` constructor:
|
|
155
|
-
|
|
156
|
-
| Extension | Provides | Keyboard shortcuts |
|
|
157
|
-
|---|---|---|
|
|
158
|
-
| `ParagraphExtension` | `paragraph` block | — |
|
|
159
|
-
| `HeadingExtension` | `heading` block (h1–h6) | `# ` → h1, `## ` → h2, ... |
|
|
160
|
-
| `ListExtension` | `list` container (bullet/ordered/todo) | — |
|
|
161
|
-
| `ListItemExtension` | `list-item` block | `Tab` indent, `Shift+Tab` unindent; `[] ` or `[x] ` → to-do list |
|
|
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` |
|
|
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 |
|
|
174
|
-
|
|
175
|
-
### Typographic substitutions
|
|
176
|
-
|
|
177
|
-
Provided by `TypographyExtension` (included in TextPreset, DocumentPreset, and FullPreset). Nabu automatically applies substitutions as you type:
|
|
178
|
-
|
|
179
|
-
| Input | Output | Description |
|
|
180
|
-
|---|---|---|
|
|
181
|
-
| `--` + space | `— ` | Em-dash (French dialogue convention) |
|
|
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:
|
|
54
|
+
Then read and write the content from the engine:
|
|
186
55
|
|
|
187
|
-
|
|
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)
|
|
56
|
+
```js test
|
|
57
|
+
import { createDocumentEditor } from '@aionbuilders/nabu';
|
|
196
58
|
|
|
197
|
-
|
|
59
|
+
const engine = createDocumentEditor();
|
|
60
|
+
await engine.importMarkdown('# Hello\n\nSome **bold** text.');
|
|
198
61
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
```js
|
|
202
|
-
// Insert blocks
|
|
203
|
-
engine.insert('paragraph', { text: 'Hello' });
|
|
204
|
-
engine.insert('heading', { level: 1, text: 'Title' });
|
|
205
|
-
engine.insert('list', { listType: 'bullet' });
|
|
206
|
-
engine.insert('dialogue', { text: 'Tu viens ce soir ?' });
|
|
207
|
-
|
|
208
|
-
// Undo / Redo
|
|
209
|
-
engine.undo();
|
|
210
|
-
engine.redo();
|
|
211
|
-
|
|
212
|
-
// Serialize
|
|
213
|
-
const markdown = engine.serialize('markdown');
|
|
214
|
-
// dialogue blocks serialize as: — Tu viens ce soir ?
|
|
215
|
-
|
|
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
|
|
62
|
+
expect(engine.serialize('markdown')).toBe('# Hello\n\nSome **bold** text.');
|
|
63
|
+
expect(engine.serialize('json').blocks).toHaveLength(2);
|
|
234
64
|
```
|
|
235
65
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
A ready-made formatting toolbar that floats above the current selection:
|
|
66
|
+
Add the optional UI from `@aionbuilders/nabu/ui`, and import a theme once:
|
|
239
67
|
|
|
240
68
|
```svelte
|
|
241
69
|
<script>
|
|
242
|
-
import
|
|
70
|
+
import '@aionbuilders/nabu/nabu-theme.css';
|
|
71
|
+
import { NabuEditor, createDocumentEditor } from '@aionbuilders/nabu';
|
|
72
|
+
import { FloatingToolbar, SlashMenu, DragHandle } from '@aionbuilders/nabu/ui';
|
|
73
|
+
|
|
243
74
|
const engine = createDocumentEditor();
|
|
244
75
|
</script>
|
|
245
76
|
|
|
246
77
|
<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
78
|
<SlashMenu {engine} />
|
|
263
|
-
<
|
|
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]} />
|
|
79
|
+
<DragHandle {engine} />
|
|
80
|
+
<NabuEditor {engine} label="Notes" />
|
|
272
81
|
```
|
|
273
82
|
|
|
274
|
-
|
|
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.
|
|
83
|
+
Save to the browser (IndexedDB) with one call, and show a document as a viewer with `readonly`:
|
|
279
84
|
|
|
280
85
|
```svelte
|
|
281
86
|
<script>
|
|
282
|
-
import { NabuEditor,
|
|
283
|
-
const engine = createFullEditor();
|
|
284
|
-
</script>
|
|
87
|
+
import { NabuEditor, createPersistedEditor } from '@aionbuilders/nabu';
|
|
285
88
|
|
|
286
|
-
|
|
287
|
-
|
|
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:
|
|
89
|
+
let engine = $state(null);
|
|
90
|
+
createPersistedEditor({ docId: 'my-notes' }).then((created) => (engine = created));
|
|
91
|
+
</script>
|
|
314
92
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
});
|
|
93
|
+
{#if engine}
|
|
94
|
+
<NabuEditor {engine} label="Notes" />
|
|
95
|
+
<!-- or, as a read-only viewer: <NabuEditor {engine} readonly /> -->
|
|
96
|
+
{/if}
|
|
336
97
|
```
|
|
337
98
|
|
|
338
|
-
|
|
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';
|
|
99
|
+
## Entry points
|
|
346
100
|
|
|
347
|
-
|
|
101
|
+
The public API is these entry points; everything else is internal and may change without notice.
|
|
348
102
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
todos.checkAll();
|
|
356
|
-
todos.uncheckAll();
|
|
357
|
-
todos.goTo(item); // move the editor cursor to a specific to-do
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
## Architecture
|
|
361
|
-
|
|
362
|
-
### Single ContentEditable
|
|
363
|
-
The entire editor lives in a single `contenteditable` root. This enables seamless cross-block selection, native copy-paste, and consistent browser performance.
|
|
103
|
+
| Import | What it is for |
|
|
104
|
+
|---|---|
|
|
105
|
+
| `@aionbuilders/nabu` | Using the editor: `NabuEditor`, the factories and presets, the built-in extensions, `createPersistedEditor`, `Files`, `Regions`, `Todos`, `deltaToMarkdown`... |
|
|
106
|
+
| `@aionbuilders/nabu/ui` | The optional UI: `FloatingToolbar`, `SlashMenu`, `DragHandle`, `CommandInvite`, `CommandChooser` |
|
|
107
|
+
| `@aionbuilders/nabu/extend` | Writing your own blocks and extensions: `extension`, `Block`, `TextBlock`, `MegaBlock`, `TextBehavior`, `RichText`, key-chord helpers |
|
|
108
|
+
| `@aionbuilders/nabu/vite` | The Vite helper `nabu()` shown above |
|
|
364
109
|
|
|
365
|
-
|
|
366
|
-
All state is stored in a [Loro](https://loro.dev) document — a WASM-based CRDT. This provides:
|
|
367
|
-
- **Local-first**: offline editing out of the box
|
|
368
|
-
- **Collaboration-ready**: conflict-free concurrent edits
|
|
369
|
-
- **Rich text**: native delta/mark support via `LoroText`
|
|
110
|
+
## Presets
|
|
370
111
|
|
|
371
|
-
|
|
372
|
-
Every block type is an extension. You can build custom block types by extending the `Block` or `MegaBlock` base classes and registering them via the `extension()` helper.
|
|
112
|
+
A preset is an array of extensions, and each has a factory.
|
|
373
113
|
|
|
374
|
-
|
|
375
|
-
|
|
114
|
+
| Preset | Factory | Contains | Tab |
|
|
115
|
+
|---|---|---|---|
|
|
116
|
+
| `MinimalPreset` | `createMinimalEditor()` | Paragraphs; plain text, HTML and Nabu paste; `BlockExtension` | leaves the editor |
|
|
117
|
+
| `TextPreset` | `createTextEditor()` | Minimal + rich text marks, typography, inline markdown shortcuts, markdown paste | leaves the editor |
|
|
118
|
+
| `DocumentPreset` | `createDocumentEditor()` | Text + headings, blockquote, divider, code, callout, toggle, image, video, file. **No lists** | stays in the editor |
|
|
119
|
+
| `FullPreset` | `createFullEditor()` | Document + lists (bullet, numbered, to-do), dialogue, regions | stays in the editor |
|
|
376
120
|
|
|
377
|
-
|
|
121
|
+
`createEditor({ preset, extensions })` is the generic factory: any preset, plus your own extensions. Details, the exact extension lists and how to add or remove extensions: [Presets](https://nabu.aion.builders/docs/getting-started/presets).
|
|
378
122
|
|
|
379
|
-
##
|
|
123
|
+
## Documentation
|
|
380
124
|
|
|
381
|
-
|
|
125
|
+
Everything is on the website: **[nabu.aion.builders/docs](https://nabu.aion.builders/docs)**.
|
|
382
126
|
|
|
383
|
-
- [
|
|
384
|
-
- [
|
|
385
|
-
- [
|
|
386
|
-
- [
|
|
387
|
-
-
|
|
388
|
-
- [
|
|
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)
|
|
127
|
+
- [Installation](https://nabu.aion.builders/docs/getting-started/installation)
|
|
128
|
+
- [Your first editor](https://nabu.aion.builders/docs/getting-started/first-editor): mounting, reading and writing content, listening to changes
|
|
129
|
+
- [Presets](https://nabu.aion.builders/docs/getting-started/presets)
|
|
130
|
+
- Guides: [Extensions](https://nabu.aion.builders/docs/guides/extensions) (including the stable `/extend` contract), [Commands and keymap](https://nabu.aion.builders/docs/guides/commands-and-keymap), [Persistence and sync](https://nabu.aion.builders/docs/guides/persistence-and-sync), [Regions](https://nabu.aion.builders/docs/guides/regions), [Accessibility](https://nabu.aion.builders/docs/guides/accessibility), [Theming](https://nabu.aion.builders/docs/guides/theming)
|
|
131
|
+
- Recipes, such as the [read-only viewer](https://nabu.aion.builders/docs/recipes/read-only-viewer)
|
|
132
|
+
- [API reference](https://nabu.aion.builders/api), [architecture](https://nabu.aion.builders/architecture) and [live labs](https://nabu.aion.builders/labs)
|
|
401
133
|
|
|
402
|
-
|
|
134
|
+
In the repository: [architecture decisions](docs/adr), [design notes](docs/design), [tests](tests/README.md).
|
|
403
135
|
|
|
404
|
-
|
|
405
|
-
- [ ] Block-selection primitive (click a drag handle to select the block as an object — insert-after / delete)
|
|
136
|
+
## License
|
|
406
137
|
|
|
407
|
-
|
|
138
|
+
MIT, as declared in `package.json`.
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
|
+
import { sanitizeUrl } from '../../utils/html.js';
|
|
3
|
+
import { linkAttributes } from '../../utils/links.js';
|
|
4
|
+
|
|
2
5
|
/** @type {{ delta: import('loro-crdt').Delta<string>[] }} */
|
|
3
6
|
let { delta } = $props();
|
|
4
7
|
|
|
@@ -13,18 +16,32 @@
|
|
|
13
16
|
].filter(Boolean).join(' ');
|
|
14
17
|
}
|
|
15
18
|
|
|
19
|
+
// Only a link to ANOTHER site opens in a new tab; the origin is read once (not known while rendering on the server: see links.js).
|
|
20
|
+
const origin = typeof location === 'undefined' ? undefined : location.origin;
|
|
21
|
+
|
|
16
22
|
const segments = $derived(delta.length ? delta : [{ insert: '\n' }]);
|
|
23
|
+
|
|
24
|
+
// A trailing "\n" does not open a visible line by itself (white-space: pre-wrap): the new line only exists once something
|
|
25
|
+
// follows the break. A filler <br> after it (ProseMirror's "trailing hack") gives that last, empty line a line box, so the
|
|
26
|
+
// caret sits on it right away. The filler is pure rendering: it holds no text, so offsets / Range.toString / the
|
|
27
|
+
// TreeWalker over text nodes ignore it; it is not in the model nor the clipboard. An EMPTY delta renders a lone "\n"
|
|
28
|
+
// text node instead (one line already) — no filler there.
|
|
29
|
+
const lastInsert = $derived(delta.length ? delta[delta.length - 1].insert : '');
|
|
30
|
+
const needsFiller = $derived(typeof lastInsert === 'string' && lastInsert.endsWith('\n'));
|
|
17
31
|
</script>
|
|
18
32
|
|
|
19
33
|
{#each segments as op}
|
|
20
|
-
{
|
|
21
|
-
|
|
34
|
+
{@const link = /** @type {any} */ (op.attributes)?.link}
|
|
35
|
+
{@const href = link ? sanitizeUrl(link, { kind: 'link' }) : null}
|
|
36
|
+
{#if href !== null}
|
|
37
|
+
{@const attrs = linkAttributes(href, origin)}
|
|
38
|
+
<a {href} class="nabu-link {getClasses(op.attributes ?? {})}" target={attrs.target} rel={attrs.rel}>{op.insert}</a>
|
|
22
39
|
{:else if op.attributes && Object.values(op.attributes).some(Boolean)}
|
|
23
40
|
<span class={getClasses(op.attributes)}>{op.insert}</span>
|
|
24
41
|
{:else}
|
|
25
42
|
{op.insert}
|
|
26
43
|
{/if}
|
|
27
|
-
{/each}
|
|
44
|
+
{/each}{#if needsFiller}<br data-nabu-filler>{/if}
|
|
28
45
|
|
|
29
46
|
<style>
|
|
30
47
|
:global(.nabu-bold) { font-weight: bold; }
|
|
@@ -32,5 +49,8 @@
|
|
|
32
49
|
:global(.nabu-underline) { text-decoration: underline; }
|
|
33
50
|
:global(.nabu-strikethrough) { text-decoration: line-through; }
|
|
34
51
|
: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, #
|
|
52
|
+
:global(.nabu-link) { color: var(--nb-link, #0b57d0); text-decoration: underline; cursor: pointer; } /* fallback 6.4:1 on white (AA text: 4.5:1); the base theme sets --nb-link for both schemes */
|
|
53
|
+
@media (prefers-color-scheme: dark) {
|
|
54
|
+
:global(.nabu-link) { color: var(--nb-link, #8ab4f8); } /* fallback 7.9:1 on #1e1e1e, 9.9:1 on black */
|
|
55
|
+
}
|
|
36
56
|
</style>
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { Extension } from '../../utils/extensions.js';
|
|
2
2
|
import { TextBehavior } from './text.behavior.svelte.js';
|
|
3
|
+
import { WORD } from './markdown-syntax.js';
|
|
4
|
+
|
|
5
|
+
// Flanking rules (CommonMark, simplified): an opening delimiter must be followed by a non-whitespace
|
|
6
|
+
// char and a closing one preceded by a non-whitespace char, so `2 * 3 * 4` and `* not *` stay literal.
|
|
7
|
+
// Only the whitespace half of CommonMark's flanking rules is implemented (no punctuation special case).
|
|
8
|
+
// `_` / `__` additionally never open or close INTRAWORD (`snake_case_name` stays literal); `*`, `~~`
|
|
9
|
+
// are allowed intraword (`a*b*c` → italic b, as in CommonMark / GFM). The paste / import parser applies the same
|
|
10
|
+
// rules (`markdown-syntax.js` `delimiterFlags`), so typing `*a*` and pasting `*a*` agree.
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Inner content of a delimited span: no `d`, non-whitespace first AND last char (a single char is fine).
|
|
14
|
+
* @param {string} d the delimiter character
|
|
15
|
+
*/
|
|
16
|
+
const inner = (d) => `[^${d}\\s](?:[^${d}]*[^${d}\\s])?`;
|
|
3
17
|
|
|
4
18
|
/**
|
|
5
19
|
* Build an inputRule that, when `closeChar` is typed and `pattern` matches the
|
|
@@ -9,9 +23,11 @@ import { TextBehavior } from './text.behavior.svelte.js';
|
|
|
9
23
|
* @param {RegExp} pattern
|
|
10
24
|
* @param {string} closeChar the closing delimiter character being typed
|
|
11
25
|
* @param {string | string[]} marks mark name(s) to apply
|
|
26
|
+
* @param {{ noIntrawordClose?: boolean }} [opts] `noIntrawordClose`: refuse to close when the char
|
|
27
|
+
* right after the cursor is a letter/digit (the closing `_` would be intraword)
|
|
12
28
|
* @returns {import('../../utils/extensions.js').InputRule}
|
|
13
29
|
*/
|
|
14
|
-
function markRule(pattern, closeChar, marks) {
|
|
30
|
+
function markRule(pattern, closeChar, marks, opts = {}) {
|
|
15
31
|
const names = Array.isArray(marks) ? marks : [marks];
|
|
16
32
|
return {
|
|
17
33
|
pattern,
|
|
@@ -19,6 +35,7 @@ function markRule(pattern, closeChar, marks) {
|
|
|
19
35
|
if (sel.data !== closeChar) return;
|
|
20
36
|
const behavior = block.behaviors.get('text');
|
|
21
37
|
if (!(behavior instanceof TextBehavior)) return;
|
|
38
|
+
if (opts.noIntrawordClose && /[\p{L}\p{N}]/u.test(behavior.text.charAt(sel.from))) return;
|
|
22
39
|
const full = match[0]; // delimiters + content present before the cursor
|
|
23
40
|
const inner = match[1]; // bare content
|
|
24
41
|
if (!inner) return;
|
|
@@ -33,22 +50,30 @@ function markRule(pattern, closeChar, marks) {
|
|
|
33
50
|
};
|
|
34
51
|
}
|
|
35
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Inline markdown shortcuts while typing: `**bold**`, `_italic_`, `` `code` ``, `~~strike~~` turn into marks as the closing delimiter is typed.
|
|
55
|
+
*/
|
|
36
56
|
export const MarkdownShortcutsExtension = new Extension('markdown-shortcuts', {
|
|
37
57
|
// ORDER MATTERS: most-specific (longest) delimiters first.
|
|
58
|
+
// The `(?<!d)` lookbehinds make an opener the START of its delimiter run: `**…*` must not fire
|
|
59
|
+
// inside `***x*` (typing `***x***`: the 2nd closing `*` used to bold `x*` and leave a stray `*`).
|
|
38
60
|
inputRules: [
|
|
39
61
|
// ***bold-italic*** (asterisks) — typed final '*' after '***x**'
|
|
40
|
-
markRule(
|
|
62
|
+
markRule(new RegExp(`(?<!\\*)\\*\\*\\*(${inner('*')})\\*\\*$`, 'u'), '*', ['bold', 'italic']),
|
|
41
63
|
// **bold** — typed final '*' after '**x*'
|
|
42
|
-
markRule(
|
|
64
|
+
markRule(new RegExp(`(?<!\\*)\\*\\*(${inner('*')})\\*$`, 'u'), '*', 'bold'),
|
|
43
65
|
// *italic* — typed final '*' after '*x' (not preceded by '*')
|
|
44
|
-
markRule(
|
|
66
|
+
markRule(new RegExp(`(?<!\\*)\\*(${inner('*')})$`, 'u'), '*', 'italic'),
|
|
67
|
+
// ___bold-italic___ (underscores, not intraword) — typed final '_' after '___x__'
|
|
68
|
+
markRule(new RegExp(`(?<![${WORD}])___(${inner('_')})__$`, 'u'), '_', ['bold', 'italic'], { noIntrawordClose: true }),
|
|
45
69
|
// __bold__ — typed final '_' after '__x_'
|
|
46
|
-
markRule(
|
|
47
|
-
// _italic_ — typed final '_' after '_x' (
|
|
48
|
-
markRule(
|
|
49
|
-
// `code` — typed final '`' after '`x'
|
|
50
|
-
|
|
70
|
+
markRule(new RegExp(`(?<![${WORD}])__(${inner('_')})_$`, 'u'), '_', 'bold', { noIntrawordClose: true }),
|
|
71
|
+
// _italic_ — typed final '_' after '_x' (opener preceded by a non-word char or the block start)
|
|
72
|
+
markRule(new RegExp(`(?<![${WORD}])_(${inner('_')})$`, 'u'), '_', 'italic', { noIntrawordClose: true }),
|
|
73
|
+
// `code` — typed final '`' after '`x'. Code spans keep inner spaces (`a b`), but need
|
|
74
|
+
// at least one non-space char and don't open inside a longer backtick run.
|
|
75
|
+
markRule(/(?<!`)`([^`]*[^`\s][^`]*)$/, '`', 'code'),
|
|
51
76
|
// ~~strike~~ — typed final '~' after '~~x~'
|
|
52
|
-
markRule(
|
|
77
|
+
markRule(new RegExp(`(?<!~)~~(${inner('~')})~$`, 'u'), '~', 'strikethrough'),
|
|
53
78
|
],
|
|
54
79
|
});
|