@aionbuilders/nabu 0.1.0-alpha.9 → 0.1.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/CHANGELOG.md +523 -0
- package/LICENSE +21 -0
- package/README.md +82 -144
- package/dist/behaviors/text/RichText.svelte +25 -2
- 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 +5 -0
- package/dist/behaviors/text/markdown-shortcuts.extension.js +79 -0
- 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 +135 -53
- package/dist/behaviors/text/text.behavior.svelte.d.ts +217 -42
- package/dist/behaviors/text/text.behavior.svelte.js +657 -55
- package/dist/behaviors/text/typography.extension.d.ts +7 -0
- package/dist/behaviors/text/typography.extension.js +25 -0
- package/dist/blocks/Block.svelte +5 -2
- package/dist/blocks/BlockList.svelte +48 -0
- package/dist/blocks/BlockList.svelte.d.ts +17 -0
- package/dist/blocks/Nabu.svelte +180 -14
- package/dist/blocks/Nabu.svelte.d.ts +13 -0
- package/dist/blocks/block.extension.d.ts +3 -0
- package/dist/blocks/block.extension.js +8 -9
- package/dist/blocks/block.svelte.d.ts +356 -68
- package/dist/blocks/block.svelte.js +388 -42
- package/dist/blocks/blockquote/Blockquote.svelte +39 -0
- package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
- package/dist/blocks/blockquote/blockquote.extension.d.ts +4 -0
- package/dist/blocks/blockquote/blockquote.extension.js +80 -0
- package/dist/blocks/blockquote/blockquote.svelte.d.ts +63 -0
- package/dist/blocks/blockquote/blockquote.svelte.js +136 -0
- package/dist/blocks/blockquote/index.d.ts +3 -0
- package/dist/blocks/blockquote/index.js +3 -0
- package/dist/blocks/callout/Callout.svelte +67 -0
- package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
- package/dist/blocks/callout/callout.extension.d.ts +4 -0
- package/dist/blocks/callout/callout.extension.js +84 -0
- package/dist/blocks/callout/callout.svelte.d.ts +80 -0
- package/dist/blocks/callout/callout.svelte.js +189 -0
- package/dist/blocks/callout/index.d.ts +3 -0
- package/dist/blocks/callout/index.js +3 -0
- package/dist/blocks/chunks.d.ts +49 -0
- package/dist/blocks/chunks.js +90 -0
- package/dist/blocks/code/Code.svelte +84 -0
- package/dist/blocks/code/Code.svelte.d.ts +11 -0
- package/dist/blocks/code/code.extension.d.ts +4 -0
- package/dist/blocks/code/code.extension.js +88 -0
- package/dist/blocks/code/code.svelte.d.ts +68 -0
- package/dist/blocks/code/code.svelte.js +245 -0
- package/dist/blocks/code/index.d.ts +3 -0
- package/dist/blocks/code/index.js +3 -0
- package/dist/blocks/container.utils.d.ts +85 -13
- package/dist/blocks/container.utils.js +338 -178
- package/dist/blocks/dialogue/Dialogue.svelte +8 -2
- package/dist/blocks/dialogue/dialogue.svelte.d.ts +36 -23
- package/dist/blocks/dialogue/dialogue.svelte.js +51 -45
- 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.svelte +28 -0
- package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
- package/dist/blocks/divider/divider.extension.d.ts +23 -0
- package/dist/blocks/divider/divider.extension.js +153 -0
- package/dist/blocks/divider/divider.svelte.d.ts +54 -0
- package/dist/blocks/divider/divider.svelte.js +89 -0
- package/dist/blocks/divider/index.d.ts +3 -0
- package/dist/blocks/divider/index.js +3 -0
- package/dist/blocks/file/File.svelte +56 -0
- package/dist/blocks/file/File.svelte.d.ts +11 -0
- package/dist/blocks/file/file.extension.d.ts +4 -0
- package/dist/blocks/file/file.extension.js +27 -0
- package/dist/blocks/file/file.svelte.d.ts +29 -0
- package/dist/blocks/file/file.svelte.js +77 -0
- package/dist/blocks/file/index.d.ts +3 -0
- package/dist/blocks/file/index.js +3 -0
- package/dist/blocks/heading/Heading.svelte +2 -1
- package/dist/blocks/heading/heading.svelte.d.ts +27 -34
- package/dist/blocks/heading/heading.svelte.js +72 -60
- 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 +41 -0
- package/dist/blocks/image/Image.svelte.d.ts +11 -0
- package/dist/blocks/image/image.extension.d.ts +5 -0
- package/dist/blocks/image/image.extension.js +34 -0
- package/dist/blocks/image/image.svelte.d.ts +61 -0
- package/dist/blocks/image/image.svelte.js +114 -0
- package/dist/blocks/image/index.d.ts +3 -0
- package/dist/blocks/image/index.js +3 -0
- package/dist/blocks/index.d.ts +11 -1
- package/dist/blocks/index.js +11 -1
- package/dist/blocks/list/List.svelte +9 -2
- package/dist/blocks/list/ListItem.svelte +44 -7
- 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 +60 -26
- 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 +7 -3
- package/dist/blocks/list/index.js +43 -31
- package/dist/blocks/list/list-item.svelte.d.ts +43 -17
- package/dist/blocks/list/list-item.svelte.js +143 -93
- package/dist/blocks/list/list.behavior.svelte.d.ts +7 -4
- package/dist/blocks/list/list.behavior.svelte.js +10 -5
- package/dist/blocks/list/list.svelte.d.ts +101 -23
- package/dist/blocks/list/list.svelte.js +136 -114
- 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/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/markdown.d.ts +12 -0
- package/dist/blocks/media/markdown.js +26 -0
- package/dist/blocks/media/media-block.svelte.d.ts +107 -0
- package/dist/blocks/media/media-block.svelte.js +181 -0
- package/dist/blocks/media/media.helpers.d.ts +24 -0
- package/dist/blocks/media/media.helpers.js +88 -0
- package/dist/blocks/megablock.svelte.d.ts +50 -19
- package/dist/blocks/megablock.svelte.js +115 -74
- package/dist/blocks/move.d.ts +23 -0
- package/dist/blocks/move.js +92 -0
- package/dist/blocks/nabu.svelte.d.ts +846 -75
- package/dist/blocks/nabu.svelte.js +1990 -182
- package/dist/blocks/paragraph/Paragraph.svelte +1 -0
- package/dist/blocks/paragraph/index.d.ts +2 -2
- package/dist/blocks/paragraph/index.js +35 -16
- package/dist/blocks/paragraph/paragraph.svelte.d.ts +49 -35
- package/dist/blocks/paragraph/paragraph.svelte.js +81 -69
- 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 +632 -74
- package/dist/blocks/subthread.d.ts +80 -0
- package/dist/blocks/subthread.js +167 -0
- package/dist/blocks/text-block.svelte.d.ts +70 -0
- package/dist/blocks/text-block.svelte.js +108 -0
- package/dist/blocks/toggle/Toggle.svelte +73 -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/markdown.d.ts +20 -0
- package/dist/blocks/toggle/markdown.js +112 -0
- package/dist/blocks/toggle/toggle.extension.d.ts +4 -0
- package/dist/blocks/toggle/toggle.extension.js +18 -0
- package/dist/blocks/toggle/toggle.svelte.d.ts +135 -0
- package/dist/blocks/toggle/toggle.svelte.js +352 -0
- package/dist/blocks/undo-selection.d.ts +175 -0
- package/dist/blocks/undo-selection.js +360 -0
- package/dist/blocks/video/Video.svelte +42 -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 +4 -0
- package/dist/blocks/video/video.extension.js +27 -0
- package/dist/blocks/video/video.svelte.d.ts +29 -0
- package/dist/blocks/video/video.svelte.js +80 -0
- 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 +363 -0
- package/dist/files/files.svelte.js +897 -0
- package/dist/files/index.d.ts +3 -0
- package/dist/files/index.js +3 -0
- 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 -6
- package/dist/index.js +117 -7
- package/dist/nabu-theme.css +112 -0
- package/dist/paste/html.paste.d.ts +74 -3
- package/dist/paste/html.paste.js +555 -83
- 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 -24
- package/dist/presets.js +51 -14
- 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 +217 -0
- package/dist/ui/DragHandle.svelte.d.ts +11 -0
- package/dist/ui/FloatingToolbar.svelte +165 -0
- package/dist/ui/FloatingToolbar.svelte.d.ts +27 -0
- package/dist/ui/SlashMenu.svelte +215 -0
- package/dist/ui/SlashMenu.svelte.d.ts +33 -0
- package/dist/ui/anchor.d.ts +112 -0
- package/dist/ui/anchor.js +136 -0
- package/dist/ui/index.d.ts +10 -0
- package/dist/ui/index.js +15 -0
- package/dist/ui/slash-menu.svelte.d.ts +112 -0
- package/dist/ui/slash-menu.svelte.js +150 -0
- 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/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 +488 -40
- package/dist/utils/extensions.js +300 -19
- package/dist/utils/html.d.ts +44 -0
- package/dist/utils/html.js +183 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +4 -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 +88 -0
- package/dist/utils/placeholders.js +91 -0
- package/dist/utils/selection.svelte.d.ts +47 -19
- 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 +7 -0
- package/dist/utils/words.js +62 -0
- package/dist/vite.d.ts +22 -0
- package/dist/vite.js +34 -0
- package/package.json +61 -22
- package/dist/blocks/zone/Zone.svelte +0 -258
- package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
- 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 -221
- package/dist/blocks/zone/zone.svelte.d.ts +0 -112
- package/dist/blocks/zone/zone.svelte.js +0 -321
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @import { Nabu, NabuNode } from '../nabu.svelte.js';
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {NabuNode<{type: "zone", synopsis: LoroText, status: string, wordCountTarget: number | null, title: string}>} ZoneNode
|
|
6
|
-
*/
|
|
7
|
-
export class ZoneBlock extends MegaBlock {
|
|
8
|
-
/**
|
|
9
|
-
* @param {Nabu} nabu
|
|
10
|
-
* @param {string} type
|
|
11
|
-
* @param {Object} [props]
|
|
12
|
-
* @param {string | null} [parentId]
|
|
13
|
-
* @param {number | null} [index]
|
|
14
|
-
*/
|
|
15
|
-
static create(nabu: Nabu, type: string, props?: Object, parentId?: string | null, index?: number | null): ZoneBlock;
|
|
16
|
-
/** @param {Nabu} nabu @param {ZoneNode} node */
|
|
17
|
-
constructor(nabu: Nabu, node: ZoneNode);
|
|
18
|
-
synopsisContainer: LoroText;
|
|
19
|
-
/** @type {string} */
|
|
20
|
-
_status: string;
|
|
21
|
-
/** @type {number | null} */
|
|
22
|
-
_wordCountTarget: number | null;
|
|
23
|
-
/** @type {string} */
|
|
24
|
-
_title: string;
|
|
25
|
-
/** @type {string} */
|
|
26
|
-
synopsisText: string;
|
|
27
|
-
zones: Zones;
|
|
28
|
-
wordCount: number;
|
|
29
|
-
set status(value: string);
|
|
30
|
-
get status(): string;
|
|
31
|
-
set wordCountTarget(value: number | null);
|
|
32
|
-
get wordCountTarget(): number | null;
|
|
33
|
-
set title(value: string);
|
|
34
|
-
get title(): string;
|
|
35
|
-
/** Returns the LoroText container for direct CRDT mutation. */
|
|
36
|
-
get synopsis(): LoroText;
|
|
37
|
-
/**
|
|
38
|
-
* Replace the synopsis text entirely.
|
|
39
|
-
* @param {string} text
|
|
40
|
-
*/
|
|
41
|
-
setSynopsis(text: string): void;
|
|
42
|
-
get clipboardProps(): {
|
|
43
|
-
status: string;
|
|
44
|
-
wordCountTarget: number | null;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Called via ascend("onSplit") when a child block's Enter key fires.
|
|
48
|
-
* Creates a new paragraph inside this Zone, never outside it.
|
|
49
|
-
*
|
|
50
|
-
* @param {Event | null} event
|
|
51
|
-
* @param {{ from: import('../block.svelte.js').Block, offset: number, delta: import('loro-crdt').Delta<string>[] }} data
|
|
52
|
-
*/
|
|
53
|
-
onSplit(event: Event | null, data: {
|
|
54
|
-
from: import("../block.svelte.js").Block;
|
|
55
|
-
offset: number;
|
|
56
|
-
delta: import("loro-crdt").Delta<string>[];
|
|
57
|
-
}): {
|
|
58
|
-
block: import("../block.svelte.js").Block;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
export class Zones {
|
|
62
|
-
/** @param {Nabu} nabu */
|
|
63
|
-
static get(nabu: Nabu): Zones;
|
|
64
|
-
/** @param {Nabu} nabu */
|
|
65
|
-
constructor(nabu: Nabu);
|
|
66
|
-
/**
|
|
67
|
-
* Flat list of all ZoneBlocks in document order (DFS traversal).
|
|
68
|
-
* @type {ZoneBlock[]}
|
|
69
|
-
*/
|
|
70
|
-
all: ZoneBlock[];
|
|
71
|
-
/**
|
|
72
|
-
* Total number of zones.
|
|
73
|
-
*/
|
|
74
|
-
count: number;
|
|
75
|
-
/**
|
|
76
|
-
* Hierarchical zone tree — zones nested inside other zones.
|
|
77
|
-
* @type {Array<{zone: ZoneBlock, children: any[]}>}
|
|
78
|
-
*/
|
|
79
|
-
tree: Array<{
|
|
80
|
-
zone: ZoneBlock;
|
|
81
|
-
children: any[];
|
|
82
|
-
}>;
|
|
83
|
-
/**
|
|
84
|
-
* The innermost zone containing the current cursor, or null if outside any zone.
|
|
85
|
-
* @type {ZoneBlock | null}
|
|
86
|
-
*/
|
|
87
|
-
current: ZoneBlock | null;
|
|
88
|
-
/**
|
|
89
|
-
* Index of the current zone in `all` (-1 if cursor is outside any zone).
|
|
90
|
-
*/
|
|
91
|
-
currentIndex: number;
|
|
92
|
-
/**
|
|
93
|
-
* Navigate to the next zone (moves cursor to its first text position).
|
|
94
|
-
*/
|
|
95
|
-
goToNext(): void;
|
|
96
|
-
/**
|
|
97
|
-
* Navigate to the previous zone.
|
|
98
|
-
*/
|
|
99
|
-
goToPrevious(): void;
|
|
100
|
-
#private;
|
|
101
|
-
}
|
|
102
|
-
export type ZoneNode = NabuNode<{
|
|
103
|
-
type: "zone";
|
|
104
|
-
synopsis: LoroText;
|
|
105
|
-
status: string;
|
|
106
|
-
wordCountTarget: number | null;
|
|
107
|
-
title: string;
|
|
108
|
-
}>;
|
|
109
|
-
import { MegaBlock } from '../megablock.svelte.js';
|
|
110
|
-
import { LoroText } from 'loro-crdt';
|
|
111
|
-
import type { Nabu } from '../nabu.svelte.js';
|
|
112
|
-
import type { NabuNode } from '../nabu.svelte.js';
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { untrack } from 'svelte';
|
|
2
|
-
import { MegaBlock } from '../megablock.svelte.js';
|
|
3
|
-
import { LoroText } from 'loro-crdt';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @import { Nabu, NabuNode } from '../nabu.svelte.js';
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {NabuNode<{type: "zone", synopsis: LoroText, status: string, wordCountTarget: number | null, title: string}>} ZoneNode
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export class ZoneBlock extends MegaBlock {
|
|
14
|
-
/** @param {Nabu} nabu @param {ZoneNode} node */
|
|
15
|
-
constructor(nabu, node) {
|
|
16
|
-
super(nabu, node);
|
|
17
|
-
|
|
18
|
-
const data = node.data;
|
|
19
|
-
|
|
20
|
-
// Synopsis LoroText — get existing or create on first construction
|
|
21
|
-
this.synopsisContainer = /** @type {LoroText} */ (
|
|
22
|
-
data.get('synopsis') ?? data.setContainer('synopsis', new LoroText())
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
// Initialize $state backing fields from Loro
|
|
26
|
-
this._status = data.get('status') ?? 'draft';
|
|
27
|
-
this._wordCountTarget = data.get('wordCountTarget') ?? null;
|
|
28
|
-
this._title = data.get('title') ?? '';
|
|
29
|
-
this.synopsisText = this.synopsisContainer.toString();
|
|
30
|
-
|
|
31
|
-
// Subscribe to map changes for reactive scalar fields
|
|
32
|
-
data.subscribe(() => {
|
|
33
|
-
this._status = data.get('status') ?? 'draft';
|
|
34
|
-
this._wordCountTarget = data.get('wordCountTarget') ?? null;
|
|
35
|
-
this._title = data.get('title') ?? '';
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Subscribe to synopsis LoroText changes
|
|
39
|
-
this.synopsisContainer.subscribe(() => {
|
|
40
|
-
this.synopsisText = this.synopsisContainer.toString();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
this.serializers.set('markdown', () => {
|
|
44
|
-
const header = `<!-- zone: ${this._status} -->`;
|
|
45
|
-
const body = this.children
|
|
46
|
-
.map(child => child.serialize('markdown'))
|
|
47
|
-
.filter(Boolean)
|
|
48
|
-
.join('\n\n');
|
|
49
|
-
return [header, body].filter(Boolean).join('\n');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
this.serializers.set('json', () => ({
|
|
53
|
-
id: this.id,
|
|
54
|
-
type: 'zone',
|
|
55
|
-
props: { status: this._status, wordCountTarget: this._wordCountTarget },
|
|
56
|
-
children: this.children.map(child => child.serialize('json')).filter(Boolean),
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
this.serializers.set('application/x-nabu+json', () => ({
|
|
60
|
-
type: 'zone',
|
|
61
|
-
props: this.clipboardProps,
|
|
62
|
-
children: this.children
|
|
63
|
-
.map(child => child.serialize('application/x-nabu+json'))
|
|
64
|
-
.filter(Boolean),
|
|
65
|
-
}));
|
|
66
|
-
|
|
67
|
-
this.zones = Zones.get(nabu);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// zones = $derived.by(() => {
|
|
74
|
-
// this.nabu.systems.has('zones');
|
|
75
|
-
// return untrack(() => Zones.get(this.nabu));
|
|
76
|
-
// });
|
|
77
|
-
|
|
78
|
-
// ── Reactive backing fields ─────────────────────────────────────────────
|
|
79
|
-
|
|
80
|
-
/** @type {string} */
|
|
81
|
-
_status = $state('draft');
|
|
82
|
-
|
|
83
|
-
/** @type {number | null} */
|
|
84
|
-
_wordCountTarget = $state(null);
|
|
85
|
-
|
|
86
|
-
/** @type {string} */
|
|
87
|
-
_title = $state('');
|
|
88
|
-
|
|
89
|
-
/** @type {string} */
|
|
90
|
-
synopsisText = $state('');
|
|
91
|
-
|
|
92
|
-
// ── Derived ─────────────────────────────────────────────────────────────
|
|
93
|
-
|
|
94
|
-
wordCount = $derived.by(() => {
|
|
95
|
-
let count = 0;
|
|
96
|
-
/** @param {import('../block.svelte.js').Block[]} blocks */
|
|
97
|
-
const traverse = (blocks) => {
|
|
98
|
-
for (const block of blocks) {
|
|
99
|
-
const tb = block.behaviors?.get('text');
|
|
100
|
-
if (tb && typeof tb.text === 'string') {
|
|
101
|
-
count += tb.text.trim().split(/\s+/).filter(Boolean).length;
|
|
102
|
-
}
|
|
103
|
-
// @ts-ignore — children exists on MegaBlock
|
|
104
|
-
if (block.children?.length) traverse(block.children);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
traverse(this.children);
|
|
108
|
-
return count;
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// ── Getters / setters ───────────────────────────────────────────────────
|
|
112
|
-
|
|
113
|
-
get status() { return this._status; }
|
|
114
|
-
set status(value) {
|
|
115
|
-
this._status = value;
|
|
116
|
-
this.node.data.set('status', value);
|
|
117
|
-
this.commit();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
get wordCountTarget() { return this._wordCountTarget; }
|
|
121
|
-
set wordCountTarget(value) {
|
|
122
|
-
this._wordCountTarget = value ?? null;
|
|
123
|
-
this.node.data.set('wordCountTarget', value ?? null);
|
|
124
|
-
this.commit();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
get title() { return this._title; }
|
|
128
|
-
set title(value) {
|
|
129
|
-
this._title = value ?? '';
|
|
130
|
-
/** @type {any} */ (this.node.data).set('title', value ?? '');
|
|
131
|
-
this.commit();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/** Returns the LoroText container for direct CRDT mutation. */
|
|
135
|
-
get synopsis() { return this.synopsisContainer; }
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Replace the synopsis text entirely.
|
|
139
|
-
* @param {string} text
|
|
140
|
-
*/
|
|
141
|
-
setSynopsis(text) {
|
|
142
|
-
const len = this.synopsisContainer.length;
|
|
143
|
-
if (len > 0) this.synopsisContainer.delete(0, len);
|
|
144
|
-
if (text) this.synopsisContainer.insert(0, text);
|
|
145
|
-
this.commit();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
get clipboardProps() {
|
|
149
|
-
return { status: this._status, wordCountTarget: this._wordCountTarget };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// ── Container split ─────────────────────────────────────────────────────
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Called via ascend("onSplit") when a child block's Enter key fires.
|
|
156
|
-
* Creates a new paragraph inside this Zone, never outside it.
|
|
157
|
-
*
|
|
158
|
-
* @param {Event | null} event
|
|
159
|
-
* @param {{ from: import('../block.svelte.js').Block, offset: number, delta: import('loro-crdt').Delta<string>[] }} data
|
|
160
|
-
*/
|
|
161
|
-
onSplit(event, data) {
|
|
162
|
-
const { from: sourceBlock, offset, delta } = data;
|
|
163
|
-
|
|
164
|
-
// Delete content from split point to end of source block
|
|
165
|
-
sourceBlock.delete({ from: offset, to: -1 });
|
|
166
|
-
|
|
167
|
-
const currentIndex = sourceBlock.node.index();
|
|
168
|
-
|
|
169
|
-
// Insert new paragraph inside THIS zone (not the zone's parent)
|
|
170
|
-
const newParagraph = this.nabu.insert(
|
|
171
|
-
'paragraph',
|
|
172
|
-
{ delta },
|
|
173
|
-
this.node.id.toString(),
|
|
174
|
-
currentIndex + 1
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
this.nabu.commit().then(() => this.nabu.selection.setCursor(newParagraph, 0));
|
|
178
|
-
return { block: newParagraph };
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// ── Static factory ──────────────────────────────────────────────────────
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* @param {Nabu} nabu
|
|
185
|
-
* @param {string} type
|
|
186
|
-
* @param {Object} [props]
|
|
187
|
-
* @param {string | null} [parentId]
|
|
188
|
-
* @param {number | null} [index]
|
|
189
|
-
*/
|
|
190
|
-
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
191
|
-
const node = nabu.tree.createNode(
|
|
192
|
-
parentId || undefined,
|
|
193
|
-
index != null ? index : undefined
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
node.data.set('type', 'zone');
|
|
197
|
-
node.data.set('status', props.status ?? 'draft');
|
|
198
|
-
node.data.set('wordCountTarget', props.wordCountTarget ?? null);
|
|
199
|
-
|
|
200
|
-
const synopsisContainer = node.data.setContainer('synopsis', new LoroText());
|
|
201
|
-
if (props.synopsis) synopsisContainer.insert(0, props.synopsis);
|
|
202
|
-
|
|
203
|
-
return new ZoneBlock(nabu, node);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export class Zones {
|
|
208
|
-
/** @type {Nabu} */
|
|
209
|
-
#nabu;
|
|
210
|
-
|
|
211
|
-
/** @param {Nabu} nabu */
|
|
212
|
-
constructor(nabu) {
|
|
213
|
-
this.#nabu = nabu;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/** @param {Nabu} nabu */
|
|
217
|
-
static get(nabu) {
|
|
218
|
-
if (!nabu.systems.has('zones')) {
|
|
219
|
-
const zones = new Zones(nabu);
|
|
220
|
-
nabu.systems.set('zones', zones);
|
|
221
|
-
return zones;
|
|
222
|
-
}
|
|
223
|
-
return /** @type {Zones} */ (nabu.systems.get('zones'));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Flat list of all ZoneBlocks in document order (DFS traversal).
|
|
228
|
-
* @type {ZoneBlock[]}
|
|
229
|
-
*/
|
|
230
|
-
all = $derived.by(() => {
|
|
231
|
-
/** @type {ZoneBlock[]} */
|
|
232
|
-
const result = [];
|
|
233
|
-
/** @param {import('../block.svelte.js').Block[]} blocks */
|
|
234
|
-
const traverse = (blocks) => {
|
|
235
|
-
for (const block of blocks) {
|
|
236
|
-
if (block.type === 'zone') result.push(/** @type {ZoneBlock} */ (block));
|
|
237
|
-
const children = /** @type {any} */ (block).children;
|
|
238
|
-
if (children?.length) traverse(children);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
traverse(this.#nabu.children);
|
|
242
|
-
return result;
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Total number of zones.
|
|
247
|
-
*/
|
|
248
|
-
count = $derived(this.all.length);
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Hierarchical zone tree — zones nested inside other zones.
|
|
252
|
-
* @type {Array<{zone: ZoneBlock, children: any[]}>}
|
|
253
|
-
*/
|
|
254
|
-
tree = $derived.by(() => {
|
|
255
|
-
/** @param {import('../block.svelte.js').Block[]} blocks */
|
|
256
|
-
const buildTree = (blocks) => {
|
|
257
|
-
/** @type {Array<{zone: ZoneBlock, children: any[]}>} */
|
|
258
|
-
const result = [];
|
|
259
|
-
for (const block of blocks) {
|
|
260
|
-
const children = /** @type {any} */ (block).children ?? [];
|
|
261
|
-
if (block.type === 'zone') {
|
|
262
|
-
result.push({ zone: /** @type {ZoneBlock} */ (block), children: buildTree(children) });
|
|
263
|
-
} else if (children.length) {
|
|
264
|
-
result.push(...buildTree(children));
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return result;
|
|
268
|
-
};
|
|
269
|
-
return buildTree(this.#nabu.children);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* The innermost zone containing the current cursor, or null if outside any zone.
|
|
274
|
-
* @type {ZoneBlock | null}
|
|
275
|
-
*/
|
|
276
|
-
current = $derived.by(() => {
|
|
277
|
-
const anchor = this.#nabu.selection.anchorBlock;
|
|
278
|
-
if (!anchor) return null;
|
|
279
|
-
let node = anchor.parent;
|
|
280
|
-
while (node) {
|
|
281
|
-
if (node.type === 'zone') return /** @type {ZoneBlock} */ (node);
|
|
282
|
-
node = node.parent;
|
|
283
|
-
}
|
|
284
|
-
return null;
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Index of the current zone in `all` (-1 if cursor is outside any zone).
|
|
289
|
-
*/
|
|
290
|
-
currentIndex = $derived.by(() => {
|
|
291
|
-
const zone = this.current;
|
|
292
|
-
if (!zone) return -1;
|
|
293
|
-
return this.all.indexOf(zone);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Navigate to the next zone (moves cursor to its first text position).
|
|
298
|
-
*/
|
|
299
|
-
goToNext() {
|
|
300
|
-
const idx = this.currentIndex;
|
|
301
|
-
const next = idx === -1
|
|
302
|
-
? this.all[0]
|
|
303
|
-
: this.all[idx + 1];
|
|
304
|
-
if (next) this.#focusZone(next);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Navigate to the previous zone.
|
|
309
|
-
*/
|
|
310
|
-
goToPrevious() {
|
|
311
|
-
const idx = this.currentIndex;
|
|
312
|
-
if (idx <= 0) return;
|
|
313
|
-
this.#focusZone(this.all[idx - 1]);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/** @param {ZoneBlock} zone */
|
|
317
|
-
#focusZone(zone) {
|
|
318
|
-
const firstChild = /** @type {any} */ (zone).children?.[0];
|
|
319
|
-
if (firstChild) this.#nabu.selection.setCursor(firstChild, 0);
|
|
320
|
-
}
|
|
321
|
-
}
|