@aionbuilders/nabu 0.1.0-beta.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/CHANGELOG.md +531 -0
  2. package/LICENSE +21 -0
  3. package/README.md +72 -341
  4. package/dist/behaviors/text/RichText.svelte +24 -4
  5. package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +3 -0
  6. package/dist/behaviors/text/markdown-shortcuts.extension.js +35 -10
  7. package/dist/behaviors/text/markdown-syntax.d.ts +42 -0
  8. package/dist/behaviors/text/markdown-syntax.js +81 -0
  9. package/dist/behaviors/text/rich-text.extension.d.ts +3 -0
  10. package/dist/behaviors/text/rich-text.extension.js +95 -38
  11. package/dist/behaviors/text/text.behavior.svelte.d.ts +195 -55
  12. package/dist/behaviors/text/text.behavior.svelte.js +531 -103
  13. package/dist/behaviors/text/typography.extension.d.ts +2 -1
  14. package/dist/behaviors/text/typography.extension.js +3 -2
  15. package/dist/blocks/BlockList.svelte +48 -0
  16. package/dist/blocks/BlockList.svelte.d.ts +17 -0
  17. package/dist/blocks/Nabu.svelte +169 -25
  18. package/dist/blocks/Nabu.svelte.d.ts +13 -0
  19. package/dist/blocks/block.extension.d.ts +3 -0
  20. package/dist/blocks/block.extension.js +4 -7
  21. package/dist/blocks/block.svelte.d.ts +350 -86
  22. package/dist/blocks/block.svelte.js +370 -59
  23. package/dist/blocks/blockquote/Blockquote.svelte +1 -2
  24. package/dist/blocks/blockquote/blockquote.extension.d.ts +4 -1
  25. package/dist/blocks/blockquote/blockquote.extension.js +14 -5
  26. package/dist/blocks/blockquote/blockquote.svelte.d.ts +19 -11
  27. package/dist/blocks/blockquote/blockquote.svelte.js +58 -13
  28. package/dist/blocks/callout/Callout.svelte +6 -8
  29. package/dist/blocks/callout/callout.extension.d.ts +4 -1
  30. package/dist/blocks/callout/callout.extension.js +19 -3
  31. package/dist/blocks/callout/callout.svelte.d.ts +5 -3
  32. package/dist/blocks/callout/callout.svelte.js +11 -6
  33. package/dist/blocks/chunks.d.ts +49 -0
  34. package/dist/blocks/chunks.js +90 -0
  35. package/dist/blocks/code/Code.svelte +7 -8
  36. package/dist/blocks/code/code.extension.d.ts +4 -1
  37. package/dist/blocks/code/code.extension.js +22 -2
  38. package/dist/blocks/code/code.svelte.d.ts +9 -2
  39. package/dist/blocks/code/code.svelte.js +49 -25
  40. package/dist/blocks/container.utils.d.ts +85 -13
  41. package/dist/blocks/container.utils.js +338 -178
  42. package/dist/blocks/dialogue/Dialogue.svelte +8 -4
  43. package/dist/blocks/dialogue/dialogue.svelte.d.ts +33 -2
  44. package/dist/blocks/dialogue/dialogue.svelte.js +58 -4
  45. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +2 -2
  46. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +6 -4
  47. package/dist/blocks/dialogue/index.d.ts +12 -1
  48. package/dist/blocks/dialogue/index.js +51 -35
  49. package/dist/blocks/divider/divider.extension.d.ts +23 -1
  50. package/dist/blocks/divider/divider.extension.js +85 -19
  51. package/dist/blocks/divider/divider.svelte.d.ts +7 -2
  52. package/dist/blocks/divider/divider.svelte.js +9 -4
  53. package/dist/blocks/file/File.svelte +13 -6
  54. package/dist/blocks/file/file.extension.d.ts +4 -1
  55. package/dist/blocks/file/file.extension.js +9 -1
  56. package/dist/blocks/file/file.svelte.d.ts +3 -3
  57. package/dist/blocks/file/file.svelte.js +20 -14
  58. package/dist/blocks/heading/Heading.svelte +1 -2
  59. package/dist/blocks/heading/heading.svelte.d.ts +23 -11
  60. package/dist/blocks/heading/heading.svelte.js +68 -13
  61. package/dist/blocks/heading/hooks/onBeforeInput.hook.js +7 -5
  62. package/dist/blocks/heading/index.d.ts +2 -2
  63. package/dist/blocks/heading/index.js +33 -8
  64. package/dist/blocks/image/Image.svelte +5 -2
  65. package/dist/blocks/image/image.extension.d.ts +4 -1
  66. package/dist/blocks/image/image.extension.js +9 -1
  67. package/dist/blocks/image/image.svelte.d.ts +17 -6
  68. package/dist/blocks/image/image.svelte.js +33 -11
  69. package/dist/blocks/index.d.ts +1 -1
  70. package/dist/blocks/index.js +1 -1
  71. package/dist/blocks/list/List.svelte +1 -0
  72. package/dist/blocks/list/ListItem.svelte +1 -0
  73. package/dist/blocks/list/convert.d.ts +20 -0
  74. package/dist/blocks/list/convert.js +92 -0
  75. package/dist/blocks/list/hooks/onBeforeInput.hook.js +49 -28
  76. package/dist/blocks/list/html-flat.d.ts +78 -0
  77. package/dist/blocks/list/html-flat.js +244 -0
  78. package/dist/blocks/list/indent.d.ts +86 -0
  79. package/dist/blocks/list/indent.js +205 -0
  80. package/dist/blocks/list/index.d.ts +6 -3
  81. package/dist/blocks/list/index.js +42 -31
  82. package/dist/blocks/list/list-item.svelte.d.ts +32 -18
  83. package/dist/blocks/list/list-item.svelte.js +99 -100
  84. package/dist/blocks/list/list.behavior.svelte.d.ts +4 -1
  85. package/dist/blocks/list/list.behavior.svelte.js +6 -1
  86. package/dist/blocks/list/list.svelte.d.ts +89 -18
  87. package/dist/blocks/list/list.svelte.js +129 -125
  88. package/dist/blocks/list/markdown.d.ts +149 -0
  89. package/dist/blocks/list/markdown.js +442 -0
  90. package/dist/blocks/list/normalize.d.ts +11 -0
  91. package/dist/blocks/list/normalize.js +396 -0
  92. package/dist/blocks/list/paste.d.ts +45 -0
  93. package/dist/blocks/list/paste.js +242 -0
  94. package/dist/blocks/list/step-back.d.ts +24 -0
  95. package/dist/blocks/list/step-back.js +87 -0
  96. package/dist/blocks/list/to-list.d.ts +7 -0
  97. package/dist/blocks/list/to-list.js +44 -0
  98. package/dist/blocks/list/todos-toggle.d.ts +20 -0
  99. package/dist/blocks/list/todos-toggle.js +48 -0
  100. package/dist/blocks/media/markdown.d.ts +12 -0
  101. package/dist/blocks/media/markdown.js +26 -0
  102. package/dist/blocks/media/media-block.svelte.d.ts +77 -2
  103. package/dist/blocks/media/media-block.svelte.js +124 -12
  104. package/dist/blocks/media/media.helpers.d.ts +6 -1
  105. package/dist/blocks/media/media.helpers.js +43 -6
  106. package/dist/blocks/megablock.svelte.d.ts +50 -19
  107. package/dist/blocks/megablock.svelte.js +114 -74
  108. package/dist/blocks/move.d.ts +23 -0
  109. package/dist/blocks/move.js +92 -0
  110. package/dist/blocks/nabu.svelte.d.ts +764 -71
  111. package/dist/blocks/nabu.svelte.js +1753 -189
  112. package/dist/blocks/paragraph/Paragraph.svelte +1 -2
  113. package/dist/blocks/paragraph/index.d.ts +2 -2
  114. package/dist/blocks/paragraph/index.js +35 -13
  115. package/dist/blocks/paragraph/paragraph.svelte.d.ts +46 -14
  116. package/dist/blocks/paragraph/paragraph.svelte.js +77 -16
  117. package/dist/blocks/paragraph/table.html.d.ts +9 -0
  118. package/dist/blocks/paragraph/table.html.js +111 -0
  119. package/dist/blocks/paragraph/table.markdown.d.ts +32 -0
  120. package/dist/blocks/paragraph/table.markdown.js +90 -0
  121. package/dist/blocks/region/Region.svelte +264 -0
  122. package/dist/blocks/region/Region.svelte.d.ts +11 -0
  123. package/dist/blocks/region/actions.d.ts +135 -0
  124. package/dist/blocks/region/actions.js +402 -0
  125. package/dist/blocks/region/close.d.ts +35 -0
  126. package/dist/blocks/region/close.js +130 -0
  127. package/dist/blocks/region/commands.d.ts +6 -0
  128. package/dist/blocks/region/commands.js +277 -0
  129. package/dist/blocks/region/create.d.ts +72 -0
  130. package/dist/blocks/region/create.js +208 -0
  131. package/dist/blocks/region/end-marker.d.ts +35 -0
  132. package/dist/blocks/region/end-marker.js +51 -0
  133. package/dist/blocks/region/facts.d.ts +69 -0
  134. package/dist/blocks/region/facts.js +152 -0
  135. package/dist/blocks/region/format.d.ts +91 -0
  136. package/dist/blocks/region/format.js +260 -0
  137. package/dist/blocks/region/index.d.ts +14 -0
  138. package/dist/blocks/region/index.js +14 -0
  139. package/dist/blocks/region/insert.d.ts +59 -0
  140. package/dist/blocks/region/insert.js +102 -0
  141. package/dist/blocks/region/messages.d.ts +254 -0
  142. package/dist/blocks/region/messages.js +131 -0
  143. package/dist/blocks/region/normalize.d.ts +7 -0
  144. package/dist/blocks/region/normalize.js +170 -0
  145. package/dist/blocks/region/region.extension.d.ts +58 -0
  146. package/dist/blocks/region/region.extension.js +119 -0
  147. package/dist/blocks/region/region.svelte.d.ts +221 -0
  148. package/dist/blocks/region/region.svelte.js +582 -0
  149. package/dist/blocks/region/regions.svelte.d.ts +141 -0
  150. package/dist/blocks/region/regions.svelte.js +276 -0
  151. package/dist/blocks/region/serialize.d.ts +57 -0
  152. package/dist/blocks/region/serialize.js +112 -0
  153. package/dist/blocks/region/types.d.ts +255 -0
  154. package/dist/blocks/region/types.js +204 -0
  155. package/dist/blocks/selection.svelte.d.ts +106 -8
  156. package/dist/blocks/selection.svelte.js +622 -74
  157. package/dist/blocks/subthread.d.ts +80 -0
  158. package/dist/blocks/subthread.js +167 -0
  159. package/dist/blocks/text-block.svelte.d.ts +35 -14
  160. package/dist/blocks/text-block.svelte.js +42 -8
  161. package/dist/blocks/toggle/Toggle.svelte +4 -15
  162. package/dist/blocks/toggle/markdown.d.ts +20 -0
  163. package/dist/blocks/toggle/markdown.js +112 -0
  164. package/dist/blocks/toggle/toggle.extension.d.ts +4 -1
  165. package/dist/blocks/toggle/toggle.extension.js +6 -0
  166. package/dist/blocks/toggle/toggle.svelte.d.ts +55 -8
  167. package/dist/blocks/toggle/toggle.svelte.js +134 -34
  168. package/dist/blocks/undo-selection.d.ts +175 -0
  169. package/dist/blocks/undo-selection.js +360 -0
  170. package/dist/blocks/video/Video.svelte +5 -2
  171. package/dist/blocks/video/video.extension.d.ts +4 -1
  172. package/dist/blocks/video/video.extension.js +9 -1
  173. package/dist/blocks/video/video.svelte.d.ts +6 -5
  174. package/dist/blocks/video/video.svelte.js +18 -9
  175. package/dist/extend.d.ts +55 -0
  176. package/dist/extend.js +88 -0
  177. package/dist/files/assets.clipboard.d.ts +77 -0
  178. package/dist/files/assets.clipboard.js +152 -0
  179. package/dist/files/files.svelte.d.ts +321 -19
  180. package/dist/files/files.svelte.js +847 -43
  181. package/dist/files/index.d.ts +3 -1
  182. package/dist/files/index.js +3 -1
  183. package/dist/files/outbox.d.ts +69 -0
  184. package/dist/files/outbox.js +48 -0
  185. package/dist/files/status.d.ts +65 -0
  186. package/dist/files/status.js +87 -0
  187. package/dist/files/store.d.ts +97 -0
  188. package/dist/files/store.js +65 -0
  189. package/dist/files/uploads.svelte.d.ts +174 -0
  190. package/dist/files/uploads.svelte.js +504 -0
  191. package/dist/index.d.ts +68 -9
  192. package/dist/index.js +117 -10
  193. package/dist/nabu-theme.css +21 -1
  194. package/dist/paste/html.paste.d.ts +74 -3
  195. package/dist/paste/html.paste.js +550 -86
  196. package/dist/paste/markdown-inline.d.ts +86 -0
  197. package/dist/paste/markdown-inline.js +528 -0
  198. package/dist/paste/markdown.paste.d.ts +2 -8
  199. package/dist/paste/markdown.paste.js +78 -94
  200. package/dist/paste/nabu.paste.d.ts +3 -0
  201. package/dist/paste/nabu.paste.js +29 -3
  202. package/dist/paste/plain-text.paste.d.ts +2 -2
  203. package/dist/paste/plain-text.paste.js +3 -3
  204. package/dist/persistence/asset-store.d.ts +51 -0
  205. package/dist/persistence/asset-store.js +103 -0
  206. package/dist/persistence/autosave.d.ts +53 -0
  207. package/dist/persistence/autosave.js +62 -0
  208. package/dist/persistence/compact.d.ts +162 -0
  209. package/dist/persistence/compact.js +141 -0
  210. package/dist/persistence/history.d.ts +77 -0
  211. package/dist/persistence/history.js +176 -0
  212. package/dist/persistence/indexeddb.d.ts +190 -4
  213. package/dist/persistence/indexeddb.js +333 -29
  214. package/dist/persistence/merge.d.ts +38 -0
  215. package/dist/persistence/merge.js +36 -0
  216. package/dist/persistence/outbox.d.ts +25 -0
  217. package/dist/persistence/outbox.js +40 -0
  218. package/dist/persistence/persistence.d.ts +70 -9
  219. package/dist/persistence/persistence.js +507 -35
  220. package/dist/persistence/recovery.d.ts +79 -0
  221. package/dist/persistence/recovery.js +79 -0
  222. package/dist/persistence/release.d.ts +34 -0
  223. package/dist/persistence/release.js +64 -0
  224. package/dist/persistence/state.svelte.d.ts +53 -0
  225. package/dist/persistence/state.svelte.js +48 -0
  226. package/dist/persistence/sync.d.ts +39 -0
  227. package/dist/persistence/sync.js +138 -0
  228. package/dist/persistence/tail.d.ts +42 -0
  229. package/dist/persistence/tail.js +103 -0
  230. package/dist/presets.d.ts +29 -26
  231. package/dist/presets.js +35 -13
  232. package/dist/themes/atelier.css +318 -0
  233. package/dist/ui/CommandChooser.svelte +153 -0
  234. package/dist/ui/CommandChooser.svelte.d.ts +13 -0
  235. package/dist/ui/CommandInvite.svelte +99 -0
  236. package/dist/ui/CommandInvite.svelte.d.ts +12 -0
  237. package/dist/ui/DragHandle.svelte +97 -21
  238. package/dist/ui/FloatingToolbar.svelte +75 -27
  239. package/dist/ui/FloatingToolbar.svelte.d.ts +10 -0
  240. package/dist/ui/SlashMenu.svelte +147 -15
  241. package/dist/ui/SlashMenu.svelte.d.ts +20 -0
  242. package/dist/ui/anchor.d.ts +112 -0
  243. package/dist/ui/anchor.js +136 -0
  244. package/dist/ui/index.d.ts +7 -1
  245. package/dist/ui/index.js +12 -1
  246. package/dist/ui/slash-menu.svelte.d.ts +79 -7
  247. package/dist/ui/slash-menu.svelte.js +85 -51
  248. package/dist/utils/command-confirm.svelte.d.ts +349 -0
  249. package/dist/utils/command-confirm.svelte.js +673 -0
  250. package/dist/utils/commands.d.ts +328 -0
  251. package/dist/utils/commands.js +416 -0
  252. package/dist/utils/composition.d.ts +28 -0
  253. package/dist/utils/composition.js +51 -0
  254. package/dist/utils/dom-scope.d.ts +14 -0
  255. package/dist/utils/dom-scope.js +20 -0
  256. package/dist/utils/drop.d.ts +160 -0
  257. package/dist/utils/drop.js +305 -0
  258. package/dist/utils/extensions.d.ts +439 -45
  259. package/dist/utils/extensions.js +271 -29
  260. package/dist/utils/html.d.ts +44 -0
  261. package/dist/utils/html.js +183 -0
  262. package/dist/utils/index.d.ts +3 -0
  263. package/dist/utils/index.js +3 -0
  264. package/dist/utils/keys.d.ts +120 -0
  265. package/dist/utils/keys.js +248 -0
  266. package/dist/utils/links.d.ts +22 -0
  267. package/dist/utils/links.js +34 -0
  268. package/dist/utils/placeholders.d.ts +81 -3
  269. package/dist/utils/placeholders.js +73 -3
  270. package/dist/utils/selection.svelte.d.ts +48 -20
  271. package/dist/utils/selection.svelte.js +60 -10
  272. package/dist/utils/spellcheck.d.ts +9 -0
  273. package/dist/utils/spellcheck.js +17 -0
  274. package/dist/utils/tab.d.ts +31 -0
  275. package/dist/utils/tab.js +117 -0
  276. package/dist/utils/words.d.ts +42 -0
  277. package/dist/utils/words.js +147 -0
  278. package/dist/vite.d.ts +9 -3
  279. package/dist/vite.js +19 -8
  280. package/package.json +56 -20
  281. package/dist/blocks/variable.svelte.d.ts +0 -47
  282. package/dist/blocks/variable.svelte.js +0 -51
  283. package/dist/blocks/zone/TemplateEditor.svelte +0 -308
  284. package/dist/blocks/zone/TemplateEditor.svelte.d.ts +0 -11
  285. package/dist/blocks/zone/Zone.svelte +0 -272
  286. package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
  287. package/dist/blocks/zone/ZoneEditor.svelte +0 -289
  288. package/dist/blocks/zone/ZoneEditor.svelte.d.ts +0 -11
  289. package/dist/blocks/zone/ZoneTemplatesList.svelte +0 -188
  290. package/dist/blocks/zone/ZoneTemplatesList.svelte.d.ts +0 -11
  291. package/dist/blocks/zone/hooks/onBeforeInput.hook.d.ts +0 -3
  292. package/dist/blocks/zone/hooks/onBeforeInput.hook.js +0 -30
  293. package/dist/blocks/zone/index.d.ts +0 -2
  294. package/dist/blocks/zone/index.js +0 -2
  295. package/dist/blocks/zone/zone.extension.d.ts +0 -2
  296. package/dist/blocks/zone/zone.extension.js +0 -237
  297. package/dist/blocks/zone/zone.svelte.d.ts +0 -221
  298. package/dist/blocks/zone/zone.svelte.js +0 -608
  299. package/dist/overlays/context/Context.svelte +0 -182
  300. package/dist/overlays/context/Context.svelte.d.ts +0 -17
  301. package/dist/overlays/context/collect.d.ts +0 -17
  302. package/dist/overlays/context/collect.js +0 -33
  303. package/dist/overlays/context/context.extension.d.ts +0 -2
  304. package/dist/overlays/context/context.extension.js +0 -8
  305. package/dist/overlays/context/context.svelte.d.ts +0 -82
  306. package/dist/overlays/context/context.svelte.js +0 -159
  307. package/dist/overlays/context/index.d.ts +0 -3
  308. package/dist/overlays/context/index.js +0 -3
@@ -0,0 +1,328 @@
1
+ /**
2
+ * @typedef {Object} CommandContext
3
+ * What the engine builds at each key press (and for `nabu.exec` of a command, with `event: null`). Extensions add FACTS
4
+ * (any other property) through `Extension#commandContext`; facts never replace the fields below.
5
+ * @property {Nabu} nabu
6
+ * @property {KeyboardEvent | null} event the key press; `null` when the command runs from `exec` / `commands.run`
7
+ * @property {import('../blocks/block.svelte.js').Block | null} block the block holding the selection anchor
8
+ * @property {import('../blocks/selection.svelte.js').NabuSelection} selection
9
+ * @property {boolean} isCollapsed
10
+ * @property {string[]} ancestors types of the ancestors of `block`, nearest first (`[]` for a root block)
11
+ * @property {boolean} inRoot `block` is a direct child of the document (not nested in a container)
12
+ */
13
+ /**
14
+ * How a command that needs confirmation asks for it before a KEY PRESS runs it (`nabu.exec(id)` / `commands.run` run it
15
+ * directly, without confirmation: the accessible path). Controller: `command-confirm.svelte.js`.
16
+ *
17
+ * - `{ strategy: 'hold', holdMs?, target?(ctx), messages? }`: hold the chord for `holdMs` (default 700, global default: the
18
+ * `commandConfirm.holdMs` init option); `target(ctx)` is what draws the progress (a block, an element).
19
+ * - `{ strategy: 'invite', inviteMs?, messages? }`: first press asks, the same chord again confirms (timeout default 5000).
20
+ * - `{ strategy: 'choose', options(ctx), footer?, messages? }`: variants; `options` returns
21
+ * `[{ id, label, display?, group?, detail?, ...any }]` and `run(nabu, ctx, option)` receives the chosen one. `group` titles
22
+ * consecutive options under a small header, `detail` is a muted right-aligned text, `footer` (a string or `(ctx) => string`)
23
+ * a hint under the list. (Several commands tying on a key use `choose` automatically.)
24
+ * - `messages`: texts of the prompt / outcome for this command (see `ConfirmMessages`).
25
+ * @typedef {{ strategy: 'hold' | 'invite' | 'choose', [option: string]: any }} CommandConfirm
26
+ */
27
+ /**
28
+ * @typedef {Object} CommandDef
29
+ * A command: a label, optional default keys, a `when` condition, a `scope` and a `run` function. Declared by extensions
30
+ * (`ExtensionInit.commands`); every command is also an action of the bus (`nabu.exec(id, data)`).
31
+ * @property {string | ((ctx: CommandContext) => string)} label text for help, prompts, pickers
32
+ * @property {string[]} [keys] default chords (`'Mod-Shift-Enter'`, see keys.js); overridable by the `keymap` option
33
+ * @property {(ctx: CommandContext) => boolean} [when] where the command applies; required for a key without modifier
34
+ * @property {string} [scope] block type the command belongs to: beats generic commands when the caret is in such a block,
35
+ * and limits the static conflict check to commands of the same scope
36
+ * @property {(nabu: Nabu, ctx: CommandContext, data?: any) => any} run a SYNCHRONOUS `false` from a key press means "not
37
+ * handled": resolution goes on (next command, legacy hooks, native behavior). Any other value (a promise included) = handled.
38
+ * @property {CommandConfirm} [confirm]
39
+ */
40
+ /**
41
+ * @typedef {Object} CommandInfo
42
+ * What `nabu.commands.list()` / `get()` return: a plain snapshot (the registry is fixed once the editor is built, so it
43
+ * needs no reactivity; read it again after a `keymap` change, i.e. a new editor).
44
+ * @property {string} id
45
+ * @property {string} label resolved (a label function is called with the given / current context)
46
+ * @property {string[]} keys the chords bound to the command, as written (`'Mod-b'`)
47
+ * @property {string[]} display `keys` formatted for the platform (`'⌘B'` / `'Ctrl+B'`)
48
+ * @property {string | undefined} scope
49
+ * @property {string} extension name of the declaring extension (`'core'` for the engine's own commands)
50
+ * @property {boolean} available `when` is true in the given / current context (true without `when`)
51
+ * @property {CommandConfirm | null} confirm
52
+ */
53
+ /**
54
+ * @typedef {Object} CommandEntry
55
+ * @property {string} id
56
+ * @property {CommandDef} def
57
+ * @property {string} extension
58
+ * @property {string | undefined} scope
59
+ * @property {string[]} keys accepted chords (as written)
60
+ * @property {number} order registration order (tie-break)
61
+ */
62
+ /**
63
+ * @typedef {Object} CommandRegistryOptions
64
+ * @property {Record<string, string[]>} [keymap] per-command replacement of the chords (`[]` disables the keys)
65
+ * @property {Platform} [platform] defaults to the detected platform
66
+ */
67
+ /**
68
+ * Holds the commands of an editor (`nabu.commands` is its public face): registers them from the extensions, resolves the keymap and
69
+ * the key chords at keydown, and answers `list`, `get`, `has` and `run`.
70
+ */
71
+ export class CommandRegistry {
72
+ /** @param {Nabu} nabu @param {CommandRegistryOptions} [options] */
73
+ constructor(nabu: Nabu, { keymap, platform }?: CommandRegistryOptions);
74
+ nabu: Nabu;
75
+ /**
76
+ * @type {Platform} `Mod` is Cmd on `'mac'`, Ctrl on `'other'`
77
+ * @public
78
+ */
79
+ public platform: Platform;
80
+ /** @type {Record<string, string[]>} */
81
+ keymap: Record<string, string[]>;
82
+ /** @type {Map<string, CommandEntry>} */
83
+ entries: Map<string, CommandEntry>;
84
+ /** canonical chord -> entries bound to it, in registration order @type {Map<string, CommandEntry[]>} */
85
+ byChord: Map<string, CommandEntry[]>;
86
+ /** @type {Array<{ extension: string, provide: (nabu: Nabu, ctx: CommandContext) => Record<string, any> | void }>} */
87
+ providers: Array<{
88
+ extension: string;
89
+ provide: (nabu: Nabu, ctx: CommandContext) => Record<string, any> | void;
90
+ }>;
91
+ /** @type {Set<string>} ambiguities already reported (once per chord + commands) */
92
+ reported: Set<string>;
93
+ counter: number;
94
+ /**
95
+ * Register a command. The command always exists (it is runnable through `exec`); only its KEYS can be refused:
96
+ * - invalid chord, or reserved by the browser / OS (see `RESERVED_CHORDS`) -> that chord is dropped, `nabu.warn`;
97
+ * - a chord without Ctrl / Alt / Meta (Backspace, Enter, a letter, Shift+letter…) on a command with no `when` -> dropped
98
+ * (it would swallow the key everywhere), `nabu.warn`;
99
+ * - the command has a `confirm` with an unknown strategy (or `choose` without `options`) -> ALL its keys dropped: a risky
100
+ * command is never run from a key without its confirmation.
101
+ * - another command with the same chord AND the same `scope` (or both unscoped) -> `nabu.warn`, both kept (the
102
+ * ambiguity is settled at key press, see {@link CommandRegistry#handleKeydown}).
103
+ * A duplicate id is refused (warning, the first registration wins). The `keymap` option replaces `def.keys`, with the
104
+ * same checks.
105
+ * @param {string} id
106
+ * @param {CommandDef} def
107
+ * @param {string} [extension]
108
+ * @returns {CommandEntry | null} null when the declaration is unusable (no `run`, duplicate id)
109
+ */
110
+ register(id: string, def: CommandDef, extension?: string): CommandEntry | null;
111
+ /**
112
+ * Warn about `keymap` entries that name no registered command (call once every extension is registered).
113
+ */
114
+ checkKeymap(): void;
115
+ /**
116
+ * Let an extension contribute FACTS to the context (`Extension#commandContext`). Facts are merged after the core fields
117
+ * and never replace them; a provider that throws is ignored (warning).
118
+ * @param {(nabu: Nabu, ctx: CommandContext) => Record<string, any> | void} provide
119
+ * @param {string} [extension]
120
+ */
121
+ addContextProvider(provide: (nabu: Nabu, ctx: CommandContext) => Record<string, any> | void, extension?: string): void;
122
+ /**
123
+ * Build the context a command sees: the core fields, then the facts of the extensions.
124
+ * @param {KeyboardEvent | null} [event]
125
+ * @returns {CommandContext}
126
+ * @public
127
+ */
128
+ public context(event?: KeyboardEvent | null): CommandContext;
129
+ /**
130
+ * Key resolution, called by `Nabu#handleKeydown` before the legacy `onKeyDown` hooks. Returns whether a command
131
+ * handled the key (the event is then `preventDefault`ed); `false` = fall through to the hooks and the native behavior.
132
+ *
133
+ * 1. nothing happens during an IME composition, or when someone already `preventDefault`ed the event;
134
+ * 2. the chord of the event (keys.js) selects the commands bound to it; none -> return (no context is even built);
135
+ * 3. candidates are the commands whose `when(ctx)` is true (absent = true; a throwing `when` = false);
136
+ * 4. ONE -> it runs, through its `confirm` strategy when it has one (the controller keeps the key from there: see
137
+ * `command-confirm.svelte.js`). SEVERAL -> a command whose `scope` is the type of the caret's block beats generic ones;
138
+ * still tied -> the `choose` strategy lets the user pick (and the ambiguity is reported once with `nabu.warn`: the
139
+ * default keys should not step on each other);
140
+ * 5. a command whose `run` returns `false` synchronously did not handle the key: the next candidate (in priority order)
141
+ * is tried, then the legacy hooks.
142
+ * @param {KeyboardEvent} event
143
+ * @returns {boolean}
144
+ */
145
+ handleKeydown(event: KeyboardEvent): boolean;
146
+ /**
147
+ * Run a command from the bus (`nabu.exec(id, data)`): no key press, `ctx.event` is `null`, `when` is not checked.
148
+ * @param {CommandEntry} entry
149
+ * @param {any} [data]
150
+ * @public
151
+ */
152
+ public invoke(entry: CommandEntry, data?: any): any;
153
+ /**
154
+ * Run a command by id, like `nabu.exec(id, data)` (which it calls).
155
+ * @param {string} id
156
+ * @param {any} [data]
157
+ * @public
158
+ */
159
+ public run(id: string, data?: any): Promise<import("@aionbuilders/pulse").PulseEvent> | undefined;
160
+ /**
161
+ * Open the confirmation of a command from code (a button, a menu, a palette, a typed trigger), as if its key had been
162
+ * pressed where `when` holds. This is the public way to start a confirmation, since `nabu.exec(id)` runs at once:
163
+ *
164
+ * - the command has a `confirm`: its prompt opens (`hold`, `invite` or `choose`, see {@link CommandConfirm}), exactly as
165
+ * for a key press: `nabu.pendingCommand`, the `CommandInvite` / `CommandChooser` components, keyboard handling and
166
+ * cancellations. Nothing has run yet; the command runs when the user confirms. `invite` expects its first key again and
167
+ * `hold` expects its first key to be held (counting from that press); both lapse after the `invite` timeout (5 s) when
168
+ * no key comes, and need the command to have a key (else nothing opens);
169
+ * - the command has NO `confirm`: there is nothing to ask, so it simply runs, like `nabu.exec(id)`, `when` checked.
170
+ *
171
+ * Returns `true` when a confirmation opened, or when a command without confirmation ran; `false` when nothing happened:
172
+ * unknown id (warning), `when` is false, no option for a `choose`, no key for a `hold` / `invite`, or a command without
173
+ * confirmation whose `run` returned `false`.
174
+ * @param {string} id command id
175
+ * @param {CommandContext} [ctx] default: the current context (`event: null`)
176
+ * @returns {boolean}
177
+ * @public
178
+ */
179
+ public offer(id: string, ctx?: CommandContext): boolean;
180
+ /**
181
+ * Every command, in registration order, as a plain snapshot (for a help sheet, a palette). Function labels and `when`
182
+ * are evaluated with `ctx` (default: the current context, `event: null`).
183
+ * @param {CommandContext} [ctx]
184
+ * @returns {CommandInfo[]}
185
+ * @public
186
+ */
187
+ public list(ctx?: CommandContext): CommandInfo[];
188
+ /**
189
+ * @param {string} id
190
+ * @param {CommandContext} [ctx]
191
+ * @returns {CommandInfo | null}
192
+ * @public
193
+ */
194
+ public get(id: string, ctx?: CommandContext): CommandInfo | null;
195
+ /**
196
+ * @param {string} id
197
+ * @returns {boolean}
198
+ * @public
199
+ */
200
+ public has(id: string): boolean;
201
+ #private;
202
+ }
203
+ /**
204
+ * What the engine builds at each key press (and for `nabu.exec` of a command, with `event: null`). Extensions add FACTS
205
+ * (any other property) through `Extension#commandContext`; facts never replace the fields below.
206
+ */
207
+ export type CommandContext = {
208
+ nabu: Nabu;
209
+ /**
210
+ * the key press; `null` when the command runs from `exec` / `commands.run`
211
+ */
212
+ event: KeyboardEvent | null;
213
+ /**
214
+ * the block holding the selection anchor
215
+ */
216
+ block: import("../blocks/block.svelte.js").Block | null;
217
+ selection: import("../blocks/selection.svelte.js").NabuSelection;
218
+ isCollapsed: boolean;
219
+ /**
220
+ * types of the ancestors of `block`, nearest first (`[]` for a root block)
221
+ */
222
+ ancestors: string[];
223
+ /**
224
+ * `block` is a direct child of the document (not nested in a container)
225
+ */
226
+ inRoot: boolean;
227
+ };
228
+ /**
229
+ * How a command that needs confirmation asks for it before a KEY PRESS runs it (`nabu.exec(id)` / `commands.run` run it
230
+ * directly, without confirmation: the accessible path). Controller: `command-confirm.svelte.js`.
231
+ *
232
+ * - `{ strategy: 'hold', holdMs?, target?(ctx), messages? }`: hold the chord for `holdMs` (default 700, global default: the
233
+ * `commandConfirm.holdMs` init option); `target(ctx)` is what draws the progress (a block, an element).
234
+ * - `{ strategy: 'invite', inviteMs?, messages? }`: first press asks, the same chord again confirms (timeout default 5000).
235
+ * - `{ strategy: 'choose', options(ctx), footer?, messages? }`: variants; `options` returns
236
+ * `[{ id, label, display?, group?, detail?, ...any }]` and `run(nabu, ctx, option)` receives the chosen one. `group` titles
237
+ * consecutive options under a small header, `detail` is a muted right-aligned text, `footer` (a string or `(ctx) => string`)
238
+ * a hint under the list. (Several commands tying on a key use `choose` automatically.)
239
+ * - `messages`: texts of the prompt / outcome for this command (see `ConfirmMessages`).
240
+ */
241
+ export type CommandConfirm = {
242
+ strategy: "hold" | "invite" | "choose";
243
+ [option: string]: any;
244
+ };
245
+ /**
246
+ * A command: a label, optional default keys, a `when` condition, a `scope` and a `run` function. Declared by extensions
247
+ * (`ExtensionInit.commands`); every command is also an action of the bus (`nabu.exec(id, data)`).
248
+ */
249
+ export type CommandDef = {
250
+ /**
251
+ * text for help, prompts, pickers
252
+ */
253
+ label: string | ((ctx: CommandContext) => string);
254
+ /**
255
+ * default chords (`'Mod-Shift-Enter'`, see keys.js); overridable by the `keymap` option
256
+ */
257
+ keys?: string[] | undefined;
258
+ /**
259
+ * where the command applies; required for a key without modifier
260
+ */
261
+ when?: ((ctx: CommandContext) => boolean) | undefined;
262
+ /**
263
+ * block type the command belongs to: beats generic commands when the caret is in such a block,
264
+ * and limits the static conflict check to commands of the same scope
265
+ */
266
+ scope?: string | undefined;
267
+ /**
268
+ * a SYNCHRONOUS `false` from a key press means "not
269
+ * handled": resolution goes on (next command, legacy hooks, native behavior). Any other value (a promise included) = handled.
270
+ */
271
+ run: (nabu: Nabu, ctx: CommandContext, data?: any) => any;
272
+ confirm?: CommandConfirm | undefined;
273
+ };
274
+ /**
275
+ * What `nabu.commands.list()` / `get()` return: a plain snapshot (the registry is fixed once the editor is built, so it
276
+ * needs no reactivity; read it again after a `keymap` change, i.e. a new editor).
277
+ */
278
+ export type CommandInfo = {
279
+ id: string;
280
+ /**
281
+ * resolved (a label function is called with the given / current context)
282
+ */
283
+ label: string;
284
+ /**
285
+ * the chords bound to the command, as written (`'Mod-b'`)
286
+ */
287
+ keys: string[];
288
+ /**
289
+ * `keys` formatted for the platform (`'⌘B'` / `'Ctrl+B'`)
290
+ */
291
+ display: string[];
292
+ scope: string | undefined;
293
+ /**
294
+ * name of the declaring extension (`'core'` for the engine's own commands)
295
+ */
296
+ extension: string;
297
+ /**
298
+ * `when` is true in the given / current context (true without `when`)
299
+ */
300
+ available: boolean;
301
+ confirm: CommandConfirm | null;
302
+ };
303
+ export type CommandEntry = {
304
+ id: string;
305
+ def: CommandDef;
306
+ extension: string;
307
+ scope: string | undefined;
308
+ /**
309
+ * accepted chords (as written)
310
+ */
311
+ keys: string[];
312
+ /**
313
+ * registration order (tie-break)
314
+ */
315
+ order: number;
316
+ };
317
+ export type CommandRegistryOptions = {
318
+ /**
319
+ * per-command replacement of the chords (`[]` disables the keys)
320
+ */
321
+ keymap?: Record<string, string[]> | undefined;
322
+ /**
323
+ * defaults to the detected platform
324
+ */
325
+ platform?: Platform | undefined;
326
+ };
327
+ import type { Nabu } from '../blocks/nabu.svelte.js';
328
+ import type { Platform } from './keys.js';