@aionbuilders/nabu 0.1.0-alpha.1 → 0.1.0-alpha.11

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.
Files changed (108) hide show
  1. package/README.md +15 -1
  2. package/dist/behaviors/text/index.d.ts +1 -1
  3. package/dist/behaviors/text/index.js +1 -1
  4. package/dist/behaviors/text/rich-text.extension.js +96 -30
  5. package/dist/behaviors/text/text.behavior.svelte.d.ts +19 -0
  6. package/dist/behaviors/text/text.behavior.svelte.js +64 -2
  7. package/dist/blocks/Block.svelte +3 -3
  8. package/dist/blocks/BlockGap.svelte +55 -0
  9. package/dist/blocks/BlockGap.svelte.d.ts +11 -0
  10. package/dist/blocks/Nabu.svelte +8 -0
  11. package/dist/blocks/block.extension.d.ts +2 -0
  12. package/dist/blocks/block.extension.js +32 -0
  13. package/dist/blocks/block.svelte.d.ts +41 -9
  14. package/dist/blocks/block.svelte.js +55 -18
  15. package/dist/blocks/container.utils.d.ts +54 -4
  16. package/dist/blocks/container.utils.js +211 -8
  17. package/dist/blocks/dialogue/Dialogue.svelte +46 -0
  18. package/dist/blocks/dialogue/Dialogue.svelte.d.ts +11 -0
  19. package/dist/blocks/dialogue/dialogue.svelte.d.ts +41 -0
  20. package/dist/blocks/dialogue/dialogue.svelte.js +87 -0
  21. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +3 -0
  22. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +52 -0
  23. package/dist/blocks/dialogue/index.d.ts +7 -0
  24. package/dist/blocks/dialogue/index.js +47 -0
  25. package/dist/blocks/heading/Heading.svelte +13 -9
  26. package/dist/blocks/heading/heading.svelte.d.ts +40 -4
  27. package/dist/blocks/heading/heading.svelte.js +60 -4
  28. package/dist/blocks/heading/hooks/onBeforeInput.hook.js +1 -1
  29. package/dist/blocks/heading/index.d.ts +2 -2
  30. package/dist/blocks/heading/index.js +11 -7
  31. package/dist/blocks/index.d.ts +7 -4
  32. package/dist/blocks/index.js +7 -4
  33. package/dist/blocks/list/ListItem.svelte +6 -2
  34. package/dist/blocks/list/hooks/onBeforeInput.hook.d.ts +3 -0
  35. package/dist/blocks/list/hooks/onBeforeInput.hook.js +77 -0
  36. package/dist/blocks/list/index.d.ts +2 -2
  37. package/dist/blocks/list/index.js +17 -3
  38. package/dist/blocks/list/list-item.svelte.d.ts +59 -6
  39. package/dist/blocks/list/list-item.svelte.js +157 -89
  40. package/dist/blocks/list/list.behavior.svelte.d.ts +1 -0
  41. package/dist/blocks/list/list.behavior.svelte.js +5 -4
  42. package/dist/blocks/list/list.svelte.d.ts +60 -7
  43. package/dist/blocks/list/list.svelte.js +116 -15
  44. package/dist/blocks/megablock.svelte.d.ts +30 -5
  45. package/dist/blocks/megablock.svelte.js +113 -17
  46. package/dist/blocks/nabu.svelte.d.ts +44 -6
  47. package/dist/blocks/nabu.svelte.js +397 -15
  48. package/dist/blocks/paragraph/Paragraph.svelte +12 -16
  49. package/dist/blocks/paragraph/Paragraph.svelte.d.ts +2 -2
  50. package/dist/blocks/paragraph/index.d.ts +2 -2
  51. package/dist/blocks/paragraph/index.js +29 -8
  52. package/dist/blocks/paragraph/paragraph.svelte.d.ts +33 -5
  53. package/dist/blocks/paragraph/paragraph.svelte.js +55 -3
  54. package/dist/blocks/selection.svelte.d.ts +6 -5
  55. package/dist/blocks/selection.svelte.js +209 -18
  56. package/dist/blocks/variable.svelte.d.ts +47 -0
  57. package/dist/blocks/variable.svelte.js +51 -0
  58. package/dist/blocks/zone/TemplateEditor.svelte +308 -0
  59. package/dist/blocks/zone/TemplateEditor.svelte.d.ts +11 -0
  60. package/dist/blocks/zone/Zone.svelte +272 -0
  61. package/dist/blocks/zone/Zone.svelte.d.ts +11 -0
  62. package/dist/blocks/zone/ZoneEditor copy.svelte +118 -0
  63. package/dist/blocks/zone/ZoneEditor copy.svelte.d.ts +11 -0
  64. package/dist/blocks/zone/ZoneEditor.svelte +289 -0
  65. package/dist/blocks/zone/ZoneEditor.svelte.d.ts +11 -0
  66. package/dist/blocks/zone/ZoneTemplatesList.svelte +188 -0
  67. package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +11 -0
  68. package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +3 -0
  69. package/dist/blocks/zone/hooks/onBeforeInput.hook.js +30 -0
  70. package/dist/blocks/zone/index.d.ts +2 -0
  71. package/dist/blocks/zone/index.js +2 -0
  72. package/dist/blocks/zone/zone.extension.d.ts +2 -0
  73. package/dist/blocks/zone/zone.extension.js +227 -0
  74. package/dist/blocks/zone/zone.svelte.d.ts +222 -0
  75. package/dist/blocks/zone/zone.svelte.js +620 -0
  76. package/dist/index.d.ts +2 -0
  77. package/dist/index.js +3 -1
  78. package/dist/nabu-theme.css +92 -0
  79. package/dist/overlays/context/Context.svelte +182 -0
  80. package/dist/overlays/context/Context.svelte.d.ts +17 -0
  81. package/dist/overlays/context/collect.d.ts +17 -0
  82. package/dist/overlays/context/collect.js +33 -0
  83. package/dist/overlays/context/context.extension.d.ts +2 -0
  84. package/dist/overlays/context/context.extension.js +8 -0
  85. package/dist/overlays/context/context.svelte.d.ts +82 -0
  86. package/dist/overlays/context/context.svelte.js +159 -0
  87. package/dist/overlays/context/index.d.ts +3 -0
  88. package/dist/overlays/context/index.js +3 -0
  89. package/dist/paste/html.paste.d.ts +12 -0
  90. package/dist/paste/html.paste.js +192 -0
  91. package/dist/paste/index.d.ts +4 -0
  92. package/dist/paste/index.js +4 -0
  93. package/dist/paste/markdown.paste.d.ts +12 -0
  94. package/dist/paste/markdown.paste.js +140 -0
  95. package/dist/paste/nabu.paste.d.ts +2 -0
  96. package/dist/paste/nabu.paste.js +20 -0
  97. package/dist/paste/plain-text.paste.d.ts +8 -0
  98. package/dist/paste/plain-text.paste.js +42 -0
  99. package/dist/persistence/indexeddb.d.ts +19 -0
  100. package/dist/persistence/indexeddb.js +71 -0
  101. package/dist/persistence/persistence.d.ts +48 -0
  102. package/dist/persistence/persistence.js +80 -0
  103. package/dist/presets.d.ts +1 -0
  104. package/dist/presets.js +18 -4
  105. package/dist/utils/extensions.d.ts +63 -0
  106. package/dist/utils/extensions.js +33 -0
  107. package/dist/utils/selection.svelte.js +0 -5
  108. package/package.json +14 -3
package/dist/presets.js CHANGED
@@ -2,23 +2,31 @@ import { Nabu } from './blocks/nabu.svelte.js';
2
2
  import { ParagraphExtension } from './blocks/paragraph/index.js';
3
3
  import { HeadingExtension } from './blocks/heading/index.js';
4
4
  import { ListExtension, ListItemExtension } from './blocks/list/index.js';
5
+ import { DialogueExtension } from './blocks/dialogue/index.js';
5
6
  import { RichTextExtension } from './behaviors/text/index.js';
7
+ import { PlainTextPasteExtension, NabuPasteExtension, HtmlPasteExtension, MarkdownPasteExtension } from './paste/index.js';
8
+ import { BlockExtension } from './blocks/block.extension.js';
9
+ import { ZoneExtension } from './blocks/zone/zone.extension.js';
10
+ import { ContextExtension } from './overlays/context/context.extension.js';
6
11
 
7
12
  // ---------------------------------------------------------------------------
8
13
  // Presets — composable extension arrays
9
14
  // ---------------------------------------------------------------------------
10
15
 
11
16
  /** Paragraph only. The simplest possible editor. */
12
- export const MinimalPreset = [ParagraphExtension];
17
+ export const MinimalPreset = [ParagraphExtension, PlainTextPasteExtension, HtmlPasteExtension, NabuPasteExtension, BlockExtension];
13
18
 
14
19
  /** Paragraph + rich text marks (bold, italic, underline, code, strikethrough). */
15
- export const TextPreset = [ParagraphExtension, RichTextExtension];
20
+ export const TextPreset = [ParagraphExtension, RichTextExtension, PlainTextPasteExtension, HtmlPasteExtension, NabuPasteExtension, MarkdownPasteExtension, BlockExtension];
16
21
 
17
22
  /** Paragraph + headings + rich text. Document-like, no lists. */
18
- export const DocumentPreset = [ParagraphExtension, HeadingExtension, RichTextExtension];
23
+ export const DocumentPreset = [ParagraphExtension, HeadingExtension, RichTextExtension, PlainTextPasteExtension, HtmlPasteExtension, MarkdownPasteExtension, NabuPasteExtension, BlockExtension];
19
24
 
20
25
  /** All built-in block types + rich text. */
21
- export const FullPreset = [ParagraphExtension, HeadingExtension, ListExtension, ListItemExtension, RichTextExtension];
26
+ export const FullPreset = [
27
+ ParagraphExtension, HeadingExtension, ListExtension, ListItemExtension, DialogueExtension, ZoneExtension, RichTextExtension, PlainTextPasteExtension, HtmlPasteExtension, MarkdownPasteExtension, NabuPasteExtension, BlockExtension,
28
+ ContextExtension
29
+ ];
22
30
 
23
31
  // ---------------------------------------------------------------------------
24
32
  // Factory — generic createEditor
@@ -70,3 +78,9 @@ export const createDocumentEditor = (options = {}) =>
70
78
  */
71
79
  export const createFullEditor = (options = {}) =>
72
80
  createEditor({ preset: FullPreset, ...options });
81
+
82
+ // ---------------------------------------------------------------------------
83
+ // Persisted factory
84
+ // ---------------------------------------------------------------------------
85
+
86
+ export { createPersistedEditor } from './persistence/persistence.js';
@@ -1,6 +1,24 @@
1
1
  /**
2
2
  * @import { Nabu, Block } from '../blocks'
3
3
  */
4
+ /**
5
+ * @typedef {Object} PasteBlock
6
+ * @property {string} type
7
+ * @property {'start' | 'end' | 'both' | false} partial
8
+ * @property {Record<string, any>} [props]
9
+ * @property {import('loro-crdt').Delta<string>[]} [delta]
10
+ * @property {PasteBlock[]} [children]
11
+ */
12
+ /**
13
+ * @typedef {Object} PasteFragment
14
+ * @property {PasteBlock[]} blocks
15
+ */
16
+ /**
17
+ * @typedef {Object} PasteInterpreter
18
+ * @property {string} format - MIME type géré ('application/x-nabu+json', 'text/html', 'text/plain')
19
+ * @property {number} [priority] - Plus haut = appelé en premier (default: 0)
20
+ * @property {(raw: string, nabu: Nabu) => PasteFragment | null} interpret
21
+ */
4
22
  /**
5
23
  * @typedef {{
6
24
  * onInit: function(Nabu): void,
@@ -21,6 +39,12 @@
21
39
  * @property {typeof Block} [block]
22
40
  * @property {Partial<ExtensionHooks>} [hooks]
23
41
  * @property {Record<string, (nabu: Nabu) => any>} [serializers]
42
+ * @property {Record<string, (nabu: Nabu, data: any, topic: string) => any>} [actions]
43
+ * @property {PasteInterpreter[]} [pasteInterpreters]
44
+ * @property {Record<string, { expand: 'after' | 'before' | 'both' | 'none' }>} [loroTextStyles]
45
+ * Loro text style configuration required by this extension.
46
+ * Passed to `LoroDoc.configTextStyle()` during Nabu initialization so that
47
+ * `applyDelta` with these attributes works correctly.
24
48
  */
25
49
  export class Extension {
26
50
  /** @param {string} name @param {ExtensionInit} init */
@@ -32,8 +56,37 @@ export class Extension {
32
56
  hooks: Partial<ExtensionHooks>;
33
57
  /** @type {Record<string, (nabu: Nabu) => any>} */
34
58
  serializers: Record<string, (nabu: Nabu) => any>;
59
+ /** @type {Record<string, (nabu: Nabu, data: any, topic: string) => any>} */
60
+ actions: Record<string, (nabu: Nabu, data: any, topic: string) => any>;
61
+ /** @type {PasteInterpreter[]} */
62
+ pasteInterpreters: PasteInterpreter[];
63
+ /** @type {Record<string, { expand: 'after' | 'before' | 'both' | 'none' }>} */
64
+ loroTextStyles: Record<string, {
65
+ expand: "after" | "before" | "both" | "none";
66
+ }>;
35
67
  }
36
68
  export function extension(name: string, init: ExtensionInit): Extension;
69
+ export type PasteBlock = {
70
+ type: string;
71
+ partial: "start" | "end" | "both" | false;
72
+ props?: Record<string, any> | undefined;
73
+ delta?: import("loro-crdt").Delta<string>[] | undefined;
74
+ children?: PasteBlock[] | undefined;
75
+ };
76
+ export type PasteFragment = {
77
+ blocks: PasteBlock[];
78
+ };
79
+ export type PasteInterpreter = {
80
+ /**
81
+ * - MIME type géré ('application/x-nabu+json', 'text/html', 'text/plain')
82
+ */
83
+ format: string;
84
+ /**
85
+ * - Plus haut = appelé en premier (default: 0)
86
+ */
87
+ priority?: number | undefined;
88
+ interpret: (raw: string, nabu: Nabu) => PasteFragment | null;
89
+ };
37
90
  export type ExtensionHooks = {
38
91
  onInit: (arg0: Nabu) => void;
39
92
  onBlockCreate: (arg0: Nabu, arg1: Block) => void;
@@ -64,6 +117,16 @@ export type ExtensionInit = {
64
117
  block?: typeof Block | undefined;
65
118
  hooks?: Partial<ExtensionHooks> | undefined;
66
119
  serializers?: Record<string, (nabu: Nabu) => any> | undefined;
120
+ actions?: Record<string, (nabu: Nabu, data: any, topic: string) => any> | undefined;
121
+ pasteInterpreters?: PasteInterpreter[] | undefined;
122
+ /**
123
+ * Loro text style configuration required by this extension.
124
+ * Passed to `LoroDoc.configTextStyle()` during Nabu initialization so that
125
+ * `applyDelta` with these attributes works correctly.
126
+ */
127
+ loroTextStyles?: Record<string, {
128
+ expand: "after" | "before" | "both" | "none";
129
+ }> | undefined;
67
130
  };
68
131
  import type { Block } from '../blocks';
69
132
  import type { Nabu } from '../blocks';
@@ -2,6 +2,27 @@
2
2
  * @import { Nabu, Block } from '../blocks'
3
3
  */
4
4
 
5
+ /**
6
+ * @typedef {Object} PasteBlock
7
+ * @property {string} type
8
+ * @property {'start' | 'end' | 'both' | false} partial
9
+ * @property {Record<string, any>} [props]
10
+ * @property {import('loro-crdt').Delta<string>[]} [delta]
11
+ * @property {PasteBlock[]} [children]
12
+ */
13
+
14
+ /**
15
+ * @typedef {Object} PasteFragment
16
+ * @property {PasteBlock[]} blocks
17
+ */
18
+
19
+ /**
20
+ * @typedef {Object} PasteInterpreter
21
+ * @property {string} format - MIME type géré ('application/x-nabu+json', 'text/html', 'text/plain')
22
+ * @property {number} [priority] - Plus haut = appelé en premier (default: 0)
23
+ * @property {(raw: string, nabu: Nabu) => PasteFragment | null} interpret
24
+ */
25
+
5
26
  /**
6
27
  * @typedef {{
7
28
  * onInit: function(Nabu): void,
@@ -23,6 +44,12 @@
23
44
  * @property {typeof Block} [block]
24
45
  * @property {Partial<ExtensionHooks>} [hooks]
25
46
  * @property {Record<string, (nabu: Nabu) => any>} [serializers]
47
+ * @property {Record<string, (nabu: Nabu, data: any, topic: string) => any>} [actions]
48
+ * @property {PasteInterpreter[]} [pasteInterpreters]
49
+ * @property {Record<string, { expand: 'after' | 'before' | 'both' | 'none' }>} [loroTextStyles]
50
+ * Loro text style configuration required by this extension.
51
+ * Passed to `LoroDoc.configTextStyle()` during Nabu initialization so that
52
+ * `applyDelta` with these attributes works correctly.
26
53
  */
27
54
 
28
55
  export class Extension {
@@ -35,6 +62,12 @@ export class Extension {
35
62
  this.hooks = init.hooks || {};
36
63
  /** @type {Record<string, (nabu: Nabu) => any>} */
37
64
  this.serializers = init.serializers || {};
65
+ /** @type {Record<string, (nabu: Nabu, data: any, topic: string) => any>} */
66
+ this.actions = init.actions || {};
67
+ /** @type {PasteInterpreter[]} */
68
+ this.pasteInterpreters = init.pasteInterpreters || [];
69
+ /** @type {Record<string, { expand: 'after' | 'before' | 'both' | 'none' }>} */
70
+ this.loroTextStyles = init.loroTextStyles || {};
38
71
  }
39
72
  }
40
73
 
@@ -519,12 +519,7 @@ export class SvelteSelection {
519
519
 
520
520
  if (relevantMutations.length === 0) return;
521
521
 
522
- // Debounce pour éviter trop d'appels
523
522
  this.#updateSelection();
524
- // clearTimeout(this.#debounceTimer);
525
- // this.#debounceTimer = setTimeout(() => {
526
- // this.#updateSelection();
527
- // }, debounceMs);
528
523
  });
529
524
  }
530
525
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aionbuilders/nabu",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.11",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",
@@ -8,7 +8,11 @@
8
8
  "prepare": "svelte-kit sync || echo ''",
9
9
  "prepack": "bunx svelte-kit sync && bunx svelte-package && bunx publint",
10
10
  "check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
11
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch"
11
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch",
12
+ "test:unit": "vitest run",
13
+ "test:unit:watch": "vitest",
14
+ "test:e2e": "playwright test",
15
+ "test": "bun run test:unit && bun run test:e2e"
12
16
  },
13
17
  "files": [
14
18
  "dist",
@@ -31,17 +35,23 @@
31
35
  "svelte": "^5.0.0"
32
36
  },
33
37
  "devDependencies": {
38
+ "@playwright/test": "^1.58.2",
34
39
  "@sveltejs/adapter-auto": "^7.0.0",
35
40
  "@sveltejs/kit": "^2.50.2",
36
41
  "@sveltejs/package": "^2.5.7",
37
42
  "@sveltejs/vite-plugin-svelte": "^6.2.4",
43
+ "playwright": "^1.58.2",
38
44
  "publint": "^0.3.17",
39
45
  "svelte": "^5.49.2",
46
+ "svelte-adapter-bun": "^1.0.1",
40
47
  "svelte-check": "^4.3.6",
41
48
  "typescript": "^5.9.3",
42
49
  "vite": "^7.3.1",
43
50
  "vite-plugin-top-level-await": "^1.6.0",
44
- "vite-plugin-wasm": "^3.5.0"
51
+ "vite-plugin-wasm": "^3.5.0",
52
+ "vitest": "^3.0.0",
53
+ "@vitest/coverage-v8": "^3.0.0",
54
+ "happy-dom": "^16.0.0"
45
55
  },
46
56
  "description": "Modular, local-first block editor engine for Svelte 5, built on a single contenteditable architecture and Loro-CRDT.",
47
57
  "author": {
@@ -69,6 +79,7 @@
69
79
  "collaborative"
70
80
  ],
71
81
  "dependencies": {
82
+ "@aionbuilders/pulse": "^1.0.1",
72
83
  "loro-crdt": "^1.10.6"
73
84
  }
74
85
  }