@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,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The heading block (levels 1 to 6): the `# ` shortcuts, the `heading:1` to `heading:6` actions and the "Heading" slash entries.
|
|
3
3
|
*/
|
|
4
|
-
export const HeadingExtension: import("
|
|
4
|
+
export const HeadingExtension: import("../../extend.js").Extension;
|
|
5
5
|
import HeadingComponent from "./Heading.svelte";
|
|
6
6
|
import { Heading } from "./heading.svelte.js";
|
|
7
7
|
export { HeadingComponent, Heading };
|
|
@@ -9,9 +9,20 @@ import { onBeforeInput } from "./hooks/onBeforeInput.hook";
|
|
|
9
9
|
* @import { Nabu } from "../nabu.svelte.js";
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
/** Total length of the text inserted by a Loro delta. @param {import('loro-crdt').Delta<string>[]} [delta] */
|
|
13
|
+
const deltaLength = (delta) => (delta || []).reduce((n, op) => n + (typeof op.insert === 'string' ? op.insert.length : 0), 0);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The heading block (levels 1 to 6): the `# ` shortcuts, the `heading:1` to `heading:6` actions and the "Heading" slash entries.
|
|
17
|
+
*/
|
|
12
18
|
const HeadingExtension = extension("heading", {
|
|
13
19
|
block: Heading,
|
|
14
20
|
component: HeadingComponent,
|
|
21
|
+
slashCommands: [
|
|
22
|
+
{ title: 'Heading 1', icon: 'H1', aliases: ['h1', 'title', 'heading'], group: 'text', order: 10, run: (e) => e.exec('heading:1') },
|
|
23
|
+
{ title: 'Heading 2', icon: 'H2', aliases: ['h2', 'subtitle'], group: 'text', order: 20, run: (e) => e.exec('heading:2') },
|
|
24
|
+
{ title: 'Heading 3', icon: 'H3', aliases: ['h3'], group: 'text', order: 30, run: (e) => e.exec('heading:3') },
|
|
25
|
+
],
|
|
15
26
|
actions: {
|
|
16
27
|
'heading:1': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 1 } }),
|
|
17
28
|
'heading:2': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 2 } }),
|
|
@@ -21,18 +32,32 @@ const HeadingExtension = extension("heading", {
|
|
|
21
32
|
'heading:6': (nabu) => nabu.exec('block:transform', { type: 'heading', props: { level: 6 } }),
|
|
22
33
|
},
|
|
23
34
|
hooks: {
|
|
24
|
-
/** @param {Nabu} nabu @param {Heading} block @param {Event} event @param {
|
|
35
|
+
/** @param {Nabu} nabu @param {Heading} block @param {Event | null} event @param {import('../../utils/extensions.js').SplitData} data */
|
|
25
36
|
onSplit: (nabu, block, event, data) => {
|
|
26
37
|
const { offset, delta } = data;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const currentIndex = block.node.index();
|
|
38
|
+
const length = block.text.length;
|
|
39
|
+
|
|
40
|
+
const currentIndex = block.node.index() ?? 0;
|
|
31
41
|
const parent = block.node.parent();
|
|
32
42
|
const parentId = parent?.id.toString() || null;
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
43
|
+
|
|
44
|
+
// START of a non-empty heading → an empty PARAGRAPH is inserted above; the heading keeps its text,
|
|
45
|
+
// its level and the caret (at the start of its text). Only when the tail is the WHOLE text (a
|
|
46
|
+
// collapsed caret): with a range selection the generic split below applies, nothing is dropped.
|
|
47
|
+
if (offset === 0 && length > 0 && deltaLength(delta) === length) {
|
|
48
|
+
nabu.insert("paragraph", {}, parentId, currentIndex);
|
|
49
|
+
block.commit().then(() => nabu.selection.setCursor(block, 0));
|
|
50
|
+
return { block };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
block.delete({from: offset, to: -1});
|
|
54
|
+
|
|
55
|
+
// END of the heading (or an EMPTY one) → a paragraph below. MIDDLE → both halves are headings of the
|
|
56
|
+
// same level.
|
|
57
|
+
const atEnd = offset >= length;
|
|
58
|
+
const newBlock = atEnd
|
|
59
|
+
? nabu.insert("paragraph", /** @type {any} */ ({ delta }), parentId, currentIndex + 1)
|
|
60
|
+
: nabu.insert("heading", /** @type {any} */ ({ delta, level: block.level }), parentId, currentIndex + 1);
|
|
36
61
|
|
|
37
62
|
block.commit().then(() => nabu.selection.setCursor(newBlock, 0));
|
|
38
63
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/** @type {{ block: import('./image.svelte.js').ImageBlock }} */
|
|
3
|
+
let { block } = $props();
|
|
4
|
+
$effect(() => block.holdSource());
|
|
5
|
+
const src = $derived(block.displaySrc);
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<figure
|
|
9
|
+
bind:this={block.element}
|
|
10
|
+
data-block-id={block.id}
|
|
11
|
+
data-block-type="image"
|
|
12
|
+
data-nabu-inert
|
|
13
|
+
contenteditable="false"
|
|
14
|
+
class="nabu-image"
|
|
15
|
+
class:selected={block.selected}
|
|
16
|
+
class:pending={block.status === 'pending'}
|
|
17
|
+
class:error={block.status === 'error'}
|
|
18
|
+
class:missing={block.isMissing}
|
|
19
|
+
>
|
|
20
|
+
{#if block.status === 'error'}
|
|
21
|
+
<div class="nabu-image-error">⚠️ Upload failed</div>
|
|
22
|
+
{:else if block.isMissing}
|
|
23
|
+
<div class="nabu-image-error nabu-image-missing" data-nabu-missing>Missing file{block.alt ? ' — ' + block.alt : ''}</div>
|
|
24
|
+
{:else if src}
|
|
25
|
+
<img src={src} alt={block.alt} draggable="false" />{#if block.status === 'pending'}<div class="nabu-image-spinner">Uploading…</div>{/if}
|
|
26
|
+
{:else}
|
|
27
|
+
<div class="nabu-image-empty">No image</div>
|
|
28
|
+
{/if}
|
|
29
|
+
</figure>
|
|
30
|
+
|
|
31
|
+
<style>
|
|
32
|
+
.nabu-image { margin: 0.5em 0; user-select: none; position: relative; display: block; max-width: 100%; }
|
|
33
|
+
.nabu-image img { max-width: 100%; height: auto; border-radius: 6px; display: block; }
|
|
34
|
+
.nabu-image.selected img { outline: 2px solid var(--nb-accent, #4d9fff); }
|
|
35
|
+
.nabu-image.pending img { opacity: 0.6; }
|
|
36
|
+
.nabu-image-spinner, .nabu-image-error, .nabu-image-empty {
|
|
37
|
+
position: absolute; inset: auto 0 0 0; padding: 4px 8px; font-size: 12px;
|
|
38
|
+
background: var(--nb-bg-surface, rgba(0,0,0,0.6)); color: var(--nb-text-primary, #fff); border-radius: 0 0 6px 6px;
|
|
39
|
+
}
|
|
40
|
+
.nabu-image-empty, .nabu-image-error { position: static; padding: 1.5em; text-align: center; border: 1px dashed var(--nb-border, rgba(255,255,255,0.2)); border-radius: 6px; color: var(--nb-text-muted, rgba(255,255,255,0.4)); }
|
|
41
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default Image;
|
|
2
|
+
type Image = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const Image: import("svelte").Component<{
|
|
7
|
+
block: import("./image.svelte.js").ImageBlock;
|
|
8
|
+
}, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
block: import("./image.svelte.js").ImageBlock;
|
|
11
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function insertImageFromFile(nabu: import("../nabu.svelte.js").Nabu, file: File): Promise<void>;
|
|
2
|
+
/**
|
|
3
|
+
* The image block: stored through the `files` option, with the `image:insert` and `image:pick` actions, image file paste and the "Image" slash entry.
|
|
4
|
+
*/
|
|
5
|
+
export const ImageExtension: import("../../extend.js").Extension;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { extension } from "../../utils/extensions";
|
|
2
|
+
import { ImageBlock } from "./image.svelte.js";
|
|
3
|
+
import ImageComponent from "./Image.svelte";
|
|
4
|
+
import { insertMediaFromFile, pickMedia, insertMediaUrl, mediaFileHandler } from "../media/media.helpers.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Insert an image block from a local File: optimistic preview → persist → ref.
|
|
8
|
+
* Re-exported for back-compat.
|
|
9
|
+
* @param {import('../nabu.svelte.js').Nabu} nabu @param {File} file
|
|
10
|
+
*/
|
|
11
|
+
export const insertImageFromFile = (nabu, file) => insertMediaFromFile(nabu, 'image', file);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The image block: stored through the `files` option, with the `image:insert` and `image:pick` actions, image file paste and the "Image" slash entry.
|
|
15
|
+
*/
|
|
16
|
+
export const ImageExtension = extension("image", {
|
|
17
|
+
// @ts-ignore — static-side variance on create()
|
|
18
|
+
block: ImageBlock,
|
|
19
|
+
component: ImageComponent,
|
|
20
|
+
// A file pasted from the clipboard becomes this block.
|
|
21
|
+
pasteFileHandlers: [mediaFileHandler('image', (file) => /^image\//i.test(file.type), 20)],
|
|
22
|
+
slashCommands: [
|
|
23
|
+
{ title: 'Image', icon: '▢', aliases: ['image', 'img', 'photo', 'picture'], group: 'media', order: 0, run: (e) => e.exec('image:pick') },
|
|
24
|
+
],
|
|
25
|
+
actions: {
|
|
26
|
+
'image:pick': (nabu) => pickMedia(nabu, 'image', 'image/*'),
|
|
27
|
+
/**
|
|
28
|
+
* Insert from a URL (external ref). data: { ref, alt? }
|
|
29
|
+
* @param {import('../nabu.svelte.js').Nabu} nabu
|
|
30
|
+
* @param {{ ref: string, alt?: string }} data
|
|
31
|
+
*/
|
|
32
|
+
'image:insert': (nabu, data) => insertMediaUrl(nabu, 'image', data),
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {NabuNode<{type: "image", ref: string, alt: string, status: string}>} ImageNode
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Void image block. Extends MediaBlock for shared void/metadata behavior.
|
|
9
|
+
* No editable text — renders an inert <figure> with a single cursor position.
|
|
10
|
+
*/
|
|
11
|
+
export class ImageBlock extends MediaBlock {
|
|
12
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
13
|
+
static toMarkdown(pb: import("../../utils/extensions.js").PasteBlock): any;
|
|
14
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
15
|
+
static toHtml(pb: import("../../utils/extensions.js").PasteBlock): string;
|
|
16
|
+
static htmlRules: {
|
|
17
|
+
selector: string;
|
|
18
|
+
embed: boolean;
|
|
19
|
+
}[];
|
|
20
|
+
/**
|
|
21
|
+
* @param {Element} el
|
|
22
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
23
|
+
*/
|
|
24
|
+
static fromHTML(el: Element): import("../../utils/extensions.js").PasteBlock | null;
|
|
25
|
+
static markdownRules: {
|
|
26
|
+
priority: number;
|
|
27
|
+
detect: RegExp;
|
|
28
|
+
consume: () => number;
|
|
29
|
+
}[];
|
|
30
|
+
/**
|
|
31
|
+
* A line that is only an image (``, `![alt][ref]`) becomes an image block; anything else
|
|
32
|
+
* (text around it, unsafe URL) returns null and falls to the paragraph rule.
|
|
33
|
+
* @param {string[]} lines
|
|
34
|
+
* @param {{ parseInlineSegments?: (text: string) => Array<{ image?: { alt: string, ref: string } }> }} [helpers]
|
|
35
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
36
|
+
*/
|
|
37
|
+
static fromMarkdown(lines: string[], helpers?: {
|
|
38
|
+
parseInlineSegments?: (text: string) => Array<{
|
|
39
|
+
image?: {
|
|
40
|
+
alt: string;
|
|
41
|
+
ref: string;
|
|
42
|
+
};
|
|
43
|
+
}>;
|
|
44
|
+
}): import("../../utils/extensions.js").PasteBlock | null;
|
|
45
|
+
/** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
46
|
+
static create(nabu: Nabu, type: string, props?: Record<string, any>, parentId?: string | null, index?: number | null): ImageBlock;
|
|
47
|
+
/** @param {Nabu} nabu @param {ImageNode} node */
|
|
48
|
+
constructor(nabu: Nabu, node: ImageNode);
|
|
49
|
+
component: import("svelte").Component<any, any, string> | import("svelte").Component<{
|
|
50
|
+
block: import("./image.svelte.js").ImageBlock;
|
|
51
|
+
}, {}, "">;
|
|
52
|
+
}
|
|
53
|
+
export type ImageNode = NabuNode<{
|
|
54
|
+
type: "image";
|
|
55
|
+
ref: string;
|
|
56
|
+
alt: string;
|
|
57
|
+
status: string;
|
|
58
|
+
}>;
|
|
59
|
+
import { MediaBlock } from "../media/media-block.svelte.js";
|
|
60
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
61
|
+
import type { NabuNode } from "../nabu.svelte.js";
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { MediaBlock } from "../media/media-block.svelte.js";
|
|
2
|
+
import { markdownImage } from "../media/markdown.js";
|
|
3
|
+
import ImageComponent from "./Image.svelte";
|
|
4
|
+
import { escapeHtml, escapeAttr, sanitizeUrl } from "../../utils/html.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {NabuNode<{type: "image", ref: string, alt: string, status: string}>} ImageNode
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Void image block. Extends MediaBlock for shared void/metadata behavior.
|
|
16
|
+
* No editable text — renders an inert <figure> with a single cursor position.
|
|
17
|
+
*/
|
|
18
|
+
// @ts-ignore — static-side variance on create()
|
|
19
|
+
export class ImageBlock extends MediaBlock {
|
|
20
|
+
/** @param {Nabu} nabu @param {ImageNode} node */
|
|
21
|
+
constructor(nabu, node) {
|
|
22
|
+
super(nabu, node);
|
|
23
|
+
|
|
24
|
+
this.serializers.set('markdown', () => ImageBlock.toMarkdown({ type: 'image', partial: false, props: this.exportProps }));
|
|
25
|
+
this.serializers.set('json', () => ({
|
|
26
|
+
id: this.id,
|
|
27
|
+
type: 'image',
|
|
28
|
+
props: this.exportProps,
|
|
29
|
+
}));
|
|
30
|
+
this.serializers.set('application/x-nabu+json', () => ({
|
|
31
|
+
type: 'image',
|
|
32
|
+
props: { ref: this.ref, alt: this.alt, ...this.clipboardState },
|
|
33
|
+
partial: false,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
component = $derived(this.nabu.components.get("image") || ImageComponent);
|
|
38
|
+
|
|
39
|
+
// ── Statics ──────────────────────────────────────────────────────────────
|
|
40
|
+
|
|
41
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
42
|
+
static toMarkdown(pb) {
|
|
43
|
+
if (!pb.props?.ref) return pb.props?.alt || ''; // no source (an embedded asset outside Nabu): the alt text only
|
|
44
|
+
return markdownImage(pb.props?.alt || '', pb.props.ref);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @param {import('../../utils/extensions.js').PasteBlock} pb */
|
|
48
|
+
static toHtml(pb) {
|
|
49
|
+
const ref = pb.props?.ref || '';
|
|
50
|
+
const src = sanitizeUrl(ref, { kind: 'media' }); // null for an empty ref too
|
|
51
|
+
const alt = pb.props?.alt || '';
|
|
52
|
+
if (src === null) return alt ? '<p>' + escapeHtml(alt) + '</p>' : ''; // unsafe / empty source: no live <img>
|
|
53
|
+
return '<img src="' + escapeAttr(src) + '" alt="' + escapeAttr(alt) + '">';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static htmlRules = [
|
|
57
|
+
// `embed`: an <img> inside a paragraph is lifted out as an image block, the text around it stays (paste/html.paste.js).
|
|
58
|
+
{ selector: 'img', embed: true },
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param {Element} el
|
|
63
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
64
|
+
*/
|
|
65
|
+
static fromHTML(el) {
|
|
66
|
+
const src = (el.getAttribute('src') || '').trim();
|
|
67
|
+
// No source (a lazy-loaded placeholder) or an unsafe one (javascript:, data:text/html…) never becomes an image block.
|
|
68
|
+
if (!src || sanitizeUrl(src, { kind: 'media' }) === null) return null;
|
|
69
|
+
return {
|
|
70
|
+
type: 'image',
|
|
71
|
+
props: {
|
|
72
|
+
ref: src,
|
|
73
|
+
alt: el.getAttribute('alt') || '',
|
|
74
|
+
},
|
|
75
|
+
partial: false,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static markdownRules = [
|
|
80
|
+
{
|
|
81
|
+
priority: 25,
|
|
82
|
+
// A line that starts with an image. `fromMarkdown` only accepts a line that IS an image; an image inside
|
|
83
|
+
// text is split out of the paragraph by the paragraph rule.
|
|
84
|
+
detect: /^!\[/,
|
|
85
|
+
consume: () => 1,
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A line that is only an image (``, `![alt][ref]`) becomes an image block; anything else
|
|
91
|
+
* (text around it, unsafe URL) returns null and falls to the paragraph rule.
|
|
92
|
+
* @param {string[]} lines
|
|
93
|
+
* @param {{ parseInlineSegments?: (text: string) => Array<{ image?: { alt: string, ref: string } }> }} [helpers]
|
|
94
|
+
* @returns {import('../../utils/extensions.js').PasteBlock | null}
|
|
95
|
+
*/
|
|
96
|
+
static fromMarkdown(lines, helpers) {
|
|
97
|
+
if (helpers?.parseInlineSegments) {
|
|
98
|
+
const segments = helpers.parseInlineSegments(lines[0].trim());
|
|
99
|
+
const image = segments.length === 1 ? segments[0].image : undefined;
|
|
100
|
+
return image ? { type: 'image', props: { alt: image.alt, ref: image.ref }, partial: false } : null;
|
|
101
|
+
}
|
|
102
|
+
const m = lines[0].match(/^!\[([^\]]*)\]\(([^)]+)\)/);
|
|
103
|
+
if (!m) return null;
|
|
104
|
+
if (sanitizeUrl(m[2].trim(), { kind: 'media' }) === null) return null; // falls back to a plain paragraph
|
|
105
|
+
return { type: 'image', props: { alt: m[1], ref: m[2] }, partial: false };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** @param {Nabu} nabu @param {string} type @param {Record<string, any>} [props={}] @param {string|null} [parentId=null] @param {number|null} [index=null] */
|
|
109
|
+
static create(nabu, type, props = {}, parentId = null, index = null) {
|
|
110
|
+
const node = MediaBlock.createNode(nabu, 'image', props, parentId, index);
|
|
111
|
+
const block = new ImageBlock(nabu, /** @type {ImageNode} */ (/** @type {unknown} */ (node)));
|
|
112
|
+
return block;
|
|
113
|
+
}
|
|
114
|
+
}
|
package/dist/blocks/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./block.svelte.js";
|
|
2
|
+
export * from "./text-block.svelte.js";
|
|
2
3
|
export * from "./block.extension.js";
|
|
3
4
|
export * from "./nabu.svelte.js";
|
|
4
5
|
export * from "./megablock.svelte.js";
|
|
@@ -7,7 +8,16 @@ export * from "./paragraph";
|
|
|
7
8
|
export * from "./heading";
|
|
8
9
|
export * from "./list";
|
|
9
10
|
export * from "./dialogue";
|
|
10
|
-
export * from "./
|
|
11
|
+
export * from "./blockquote";
|
|
12
|
+
export * from "./divider";
|
|
13
|
+
export * from "./code";
|
|
14
|
+
export * from "./callout";
|
|
15
|
+
export * from "./toggle";
|
|
16
|
+
export * from "./image";
|
|
17
|
+
export * from "./media";
|
|
18
|
+
export * from "./video";
|
|
19
|
+
export * from "./file";
|
|
20
|
+
export * from "./region";
|
|
11
21
|
export * from "./selection.svelte.js";
|
|
12
22
|
export { default as NabuEditor } from "./Nabu.svelte";
|
|
13
23
|
export { default as BlockComponent } from "./Block.svelte";
|
package/dist/blocks/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./block.svelte.js";
|
|
2
|
+
export * from "./text-block.svelte.js";
|
|
2
3
|
export * from "./block.extension.js";
|
|
3
4
|
export * from "./nabu.svelte.js";
|
|
4
5
|
export * from "./megablock.svelte.js";
|
|
@@ -10,6 +11,15 @@ export * from "./paragraph";
|
|
|
10
11
|
export * from "./heading";
|
|
11
12
|
export * from "./list";
|
|
12
13
|
export * from "./dialogue";
|
|
13
|
-
export * from "./
|
|
14
|
+
export * from "./blockquote";
|
|
15
|
+
export * from "./divider";
|
|
16
|
+
export * from "./code";
|
|
17
|
+
export * from "./callout";
|
|
18
|
+
export * from "./toggle";
|
|
19
|
+
export * from "./image";
|
|
20
|
+
export * from "./media";
|
|
21
|
+
export * from "./video";
|
|
22
|
+
export * from "./file";
|
|
23
|
+
export * from "./region";
|
|
14
24
|
|
|
15
25
|
export * from "./selection.svelte.js";
|
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
let {block} = $props();
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
|
-
<svelte:element
|
|
9
|
-
this={block.listType === 'ordered' ? 'ol' : 'ul'}
|
|
8
|
+
<svelte:element
|
|
9
|
+
this={block.listType === 'ordered' ? 'ol' : 'ul'}
|
|
10
|
+
start={block.listType === 'ordered' ? (block.start ?? undefined) : undefined}
|
|
10
11
|
data-block-id={block.id}
|
|
11
12
|
data-block-type="list"
|
|
12
13
|
class="nabu-list"
|
|
14
|
+
class:todo={block.listType === 'todo'}
|
|
13
15
|
>
|
|
14
16
|
{#each block.children as child (child.id)}
|
|
15
17
|
<Block block={child} />
|
|
@@ -22,4 +24,9 @@
|
|
|
22
24
|
margin-bottom: 0.5rem;
|
|
23
25
|
padding-left: 1.5rem;
|
|
24
26
|
}
|
|
27
|
+
|
|
28
|
+
.nabu-list.todo {
|
|
29
|
+
list-style: none;
|
|
30
|
+
padding-left: 0;
|
|
31
|
+
}
|
|
25
32
|
</style>
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
let {block} = $props();
|
|
7
7
|
</script>
|
|
8
8
|
|
|
9
|
-
<li
|
|
9
|
+
<li
|
|
10
10
|
data-block-id={block.id}
|
|
11
11
|
data-block-type="list-item"
|
|
12
12
|
class="nabu-list-item"
|
|
@@ -14,8 +14,16 @@
|
|
|
14
14
|
class:selected={block.selected}
|
|
15
15
|
class:first={block.isSelectionStart}
|
|
16
16
|
class:last={block.isSelectionEnd}
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
class:todo={block.isTodo}
|
|
18
|
+
>{#if block.isTodo}<button
|
|
19
|
+
class="nabu-todo-check"
|
|
20
|
+
data-nabu-ui
|
|
21
|
+
contenteditable="false"
|
|
22
|
+
type="button"
|
|
23
|
+
aria-pressed={block.checked}
|
|
24
|
+
aria-disabled={block.nabu.readonly ? 'true' : undefined}
|
|
25
|
+
onmousedown={(e) => { e.preventDefault(); block.toggleChecked(); }}
|
|
26
|
+
>{block.checked ? '☑' : '☐'}</button>{/if}<div bind:this={block.element} class="item-content" class:checked={block.checked}><RichText delta={block.delta} /></div><!--
|
|
19
27
|
-->{#if block.children && block.children.length > 0}
|
|
20
28
|
<div class="item-children">
|
|
21
29
|
{#each block.children as child (child.id)}
|
|
@@ -28,22 +36,51 @@
|
|
|
28
36
|
<style>
|
|
29
37
|
.nabu-list-item {
|
|
30
38
|
margin: 0.25rem 0;
|
|
31
|
-
|
|
39
|
+
|
|
32
40
|
&.debug{
|
|
33
41
|
&.selected > .item-content {
|
|
34
42
|
background-color: rgba(59, 130, 246, 0.25);
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
|
-
|
|
45
|
+
|
|
46
|
+
&.todo {
|
|
47
|
+
display: flex;
|
|
48
|
+
flex-wrap: wrap;
|
|
49
|
+
align-items: flex-start;
|
|
50
|
+
gap: 0.2em 0.4em;
|
|
51
|
+
}
|
|
52
|
+
/* Checkbox + content share line 1; a nested sublist wraps to its own
|
|
53
|
+
full-width line below (without flex-wrap it would sit to the right). */
|
|
54
|
+
&.todo > .item-content { flex: 1; min-width: 0; }
|
|
55
|
+
&.todo > .item-children { flex-basis: 100%; }
|
|
38
56
|
}
|
|
39
|
-
|
|
57
|
+
|
|
40
58
|
.item-content {
|
|
41
59
|
outline: none;
|
|
42
60
|
white-space: pre-wrap;
|
|
43
61
|
min-height: 1.5em; /* Permet de cliquer dans un item vide */
|
|
62
|
+
|
|
63
|
+
&.checked {
|
|
64
|
+
text-decoration: line-through;
|
|
65
|
+
opacity: 0.55;
|
|
66
|
+
}
|
|
44
67
|
}
|
|
45
|
-
|
|
68
|
+
|
|
46
69
|
.item-children {
|
|
47
70
|
/* Pas de margin-left ici, c'est le <ul> imbriqué qui gèrera l'indentation */
|
|
48
71
|
}
|
|
72
|
+
|
|
73
|
+
.nabu-todo-check {
|
|
74
|
+
flex-shrink: 0;
|
|
75
|
+
background: none;
|
|
76
|
+
border: none;
|
|
77
|
+
padding: 0;
|
|
78
|
+
margin: 0;
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
user-select: none;
|
|
81
|
+
font-size: 1em;
|
|
82
|
+
line-height: 1.5;
|
|
83
|
+
outline: none;
|
|
84
|
+
vertical-align: top;
|
|
85
|
+
}
|
|
49
86
|
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns an item into a block that is not a list item (see the file header). Moves only; no commit.
|
|
3
|
+
* @param {Nabu} nabu
|
|
4
|
+
* @param {NabuNode} item a list-item node
|
|
5
|
+
* @param {string} type
|
|
6
|
+
* @param {Record<string, any>} [props]
|
|
7
|
+
* @param {boolean} [numbered=true] see `liftItemTo`
|
|
8
|
+
* @returns {boolean} whether the item was retyped
|
|
9
|
+
*/
|
|
10
|
+
export function retypeItem(nabu: Nabu, item: NabuNode, type: string, props?: Record<string, any>, numbered?: boolean): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Moves an item to a list of another type (see the file header). Moves only; no commit.
|
|
13
|
+
* @param {Nabu} nabu
|
|
14
|
+
* @param {NabuNode} item a list-item node
|
|
15
|
+
* @param {"bullet" | "ordered" | "todo"} listType
|
|
16
|
+
* @returns {boolean} whether something changed (false: already of that type, or not in a list)
|
|
17
|
+
*/
|
|
18
|
+
export function convertItemToListType(nabu: Nabu, item: NabuNode, listType: "bullet" | "ordered" | "todo"): boolean;
|
|
19
|
+
import type { Nabu } from "../nabu.svelte.js";
|
|
20
|
+
import type { NabuNode } from "../nabu.svelte.js";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Changing the TYPE of ONE list item, in place: the rest of the list is not touched.
|
|
3
|
+
*
|
|
4
|
+
* - to another LIST type (bullet / ordered / todo): the item (with its sublists) goes into a new list of the
|
|
5
|
+
* target type, placed between the part of the list before it and the part after it (both keep their
|
|
6
|
+
* type; an ORDERED tail keeps counting through `start`). Adjacent lists of the same type are merged by the
|
|
7
|
+
* normalizer afterwards. The same type is a no-op. Entering a todo list sets `checked: false`, leaving
|
|
8
|
+
* one drops `checked`.
|
|
9
|
+
* This works at ANY nesting level (P-28): inside a sublist the three parts are sublists of the same
|
|
10
|
+
* parent item, in place, side by side (`a > [ul[s1], ol[s2], ul[s3]]`); nothing is promoted. A sole child
|
|
11
|
+
* converted to another list type just changes the type of its list (which the normalizer then merges with
|
|
12
|
+
* an adjacent sublist of the new type).
|
|
13
|
+
* - to any other block (paragraph, heading, quote, code…): the item leaves its list exactly like the
|
|
14
|
+
* top-level Backspace (see step-back.js `liftItemTo`). A NESTED item cannot become a non-list block where it
|
|
15
|
+
* is (a list only holds items), so it is first unindented up to the top level (exactly what repeated
|
|
16
|
+
* Shift+Tab / Backspace do: the following siblings, level after level, become its children, so the
|
|
17
|
+
* document order and every item survive) and then lifted as a top-level item.
|
|
18
|
+
*
|
|
19
|
+
* Moves on tree NODES only, no commit (the caller owns the transaction, hence the undo step).
|
|
20
|
+
*
|
|
21
|
+
* @import { Nabu, NabuNode } from "../nabu.svelte.js";
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { List, listStart } from "./list.svelte.js";
|
|
25
|
+
import { typeOf, kids, listTypeOf, dropIfEmpty, unindentNode } from "./indent.js";
|
|
26
|
+
import { liftItemTo } from "./step-back.js";
|
|
27
|
+
|
|
28
|
+
/** Whether the item sits in a sublist of another item. @param {NabuNode} item */
|
|
29
|
+
const isNested = (item) => typeOf(item.parent()?.parent()) === "list-item";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Unindents a nested item until it is top-level. Moves only.
|
|
33
|
+
* @param {Nabu} nabu
|
|
34
|
+
* @param {NabuNode} item
|
|
35
|
+
*/
|
|
36
|
+
function hoistToTopLevel(nabu, item) {
|
|
37
|
+
while (isNested(item)) if (!unindentNode(nabu, item)) break;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Turns an item into a block that is not a list item (see the file header). Moves only; no commit.
|
|
42
|
+
* @param {Nabu} nabu
|
|
43
|
+
* @param {NabuNode} item a list-item node
|
|
44
|
+
* @param {string} type
|
|
45
|
+
* @param {Record<string, any>} [props]
|
|
46
|
+
* @param {boolean} [numbered=true] see `liftItemTo`
|
|
47
|
+
* @returns {boolean} whether the item was retyped
|
|
48
|
+
*/
|
|
49
|
+
export function retypeItem(nabu, item, type, props = {}, numbered = true) {
|
|
50
|
+
if (type === "list-item") return false;
|
|
51
|
+
hoistToTopLevel(nabu, item);
|
|
52
|
+
return liftItemTo(nabu, item, type, props, numbered);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Moves an item to a list of another type (see the file header). Moves only; no commit.
|
|
57
|
+
* @param {Nabu} nabu
|
|
58
|
+
* @param {NabuNode} item a list-item node
|
|
59
|
+
* @param {"bullet" | "ordered" | "todo"} listType
|
|
60
|
+
* @returns {boolean} whether something changed (false: already of that type, or not in a list)
|
|
61
|
+
*/
|
|
62
|
+
export function convertItemToListType(nabu, item, listType) {
|
|
63
|
+
const list = item.parent();
|
|
64
|
+
if (!list || typeOf(list) !== "list" || listTypeOf(list) === listType) return false;
|
|
65
|
+
const current = listTypeOf(list);
|
|
66
|
+
const data = /** @type {any} */ (item.data);
|
|
67
|
+
if (kids(list).length === 1) {
|
|
68
|
+
// The only item: the list itself changes type.
|
|
69
|
+
/** @type {any} */ (list.data).set("listType", listType);
|
|
70
|
+
if (listType !== "ordered" && /** @type {any} */ (list.data).get("start") !== undefined) /** @type {any} */ (list.data).delete("start");
|
|
71
|
+
} else {
|
|
72
|
+
const index = item.index() ?? 0;
|
|
73
|
+
const followers = kids(list).slice(index + 1);
|
|
74
|
+
const parentId = list.parent()?.id.toString() ?? null;
|
|
75
|
+
// The number the first follower had: the list's own start + the items before it (item included).
|
|
76
|
+
const tailStart = (listStart(current, /** @type {any} */ (list.data).get("start")) ?? 1) + index + 1;
|
|
77
|
+
// List.create, not nabu.insert(): that commits, and the empty list would be normalized away.
|
|
78
|
+
const middle = List.create(nabu, "list", { listType }, parentId).node;
|
|
79
|
+
middle.moveAfter(list);
|
|
80
|
+
item.move(middle, 0);
|
|
81
|
+
if (followers.length) {
|
|
82
|
+
const tail = List.create(nabu, "list", { listType: current, start: tailStart }, parentId).node;
|
|
83
|
+
tail.moveAfter(middle);
|
|
84
|
+
for (const follower of followers) follower.move(tail, kids(tail).length);
|
|
85
|
+
}
|
|
86
|
+
dropIfEmpty(nabu, list);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (listType === "todo") data.set("checked", false);
|
|
90
|
+
else if (data.get("checked") !== undefined) data.delete("checked");
|
|
91
|
+
return true;
|
|
92
|
+
}
|