bookish-press 0.4.46 → 0.4.47

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 (533) hide show
  1. package/.env.example +8 -0
  2. package/.firebaserc +8 -0
  3. package/.prettierignore +8 -0
  4. package/.prettierrc.json +5 -0
  5. package/_update-notifier-last-checked +0 -0
  6. package/firebase.json +46 -0
  7. package/firestore.indexes.json +4 -0
  8. package/firestore.rules +59 -0
  9. package/functions/.eslintrc.js +28 -0
  10. package/functions/package-lock.json +12595 -0
  11. package/functions/package.json +43 -0
  12. package/functions/src/index.ts +345 -0
  13. package/functions/tsconfig.dev.json +3 -0
  14. package/functions/tsconfig.json +15 -0
  15. package/package.json +53 -270
  16. package/scripts/claims.cjs +99 -0
  17. package/src/app.d.ts +9 -0
  18. package/src/app.html +24 -0
  19. package/src/lib/components/Auth.svelte +65 -0
  20. package/{components/Authentication.d.ts → src/lib/components/Authentication.ts} +2 -0
  21. package/{components → src/lib/components}/BookPreview.svelte +27 -22
  22. package/{components → src/lib/components}/External.svelte +2 -1
  23. package/src/lib/components/Link.svelte +58 -0
  24. package/{components → src/lib/components}/app/BookList.svelte +6 -3
  25. package/{components → src/lib/components}/app/Button.svelte +5 -4
  26. package/{components → src/lib/components}/app/Feedback.svelte +11 -7
  27. package/{components → src/lib/components}/app/Head.svelte +2 -1
  28. package/{components → src/lib/components}/app/Large.svelte +0 -0
  29. package/{components → src/lib/components}/app/Lead.svelte +0 -0
  30. package/{components → src/lib/components}/app/Link.svelte +4 -3
  31. package/{components → src/lib/components}/app/Options.svelte +5 -4
  32. package/{components → src/lib/components}/app/Paragraph.svelte +2 -1
  33. package/{components → src/lib/components}/app/Section.svelte +0 -0
  34. package/{components → src/lib/components}/app/Table.svelte +0 -0
  35. package/{components → src/lib/components}/app/TextInput.svelte +12 -9
  36. package/{components → src/lib/components}/chapter/Atom.svelte +18 -12
  37. package/src/lib/components/chapter/Block.svelte +42 -0
  38. package/{components → src/lib/components}/chapter/Callout.svelte +6 -3
  39. package/{components → src/lib/components}/chapter/CaptionedCode.svelte +21 -13
  40. package/{components → src/lib/components}/chapter/ChapterBody.svelte +13 -9
  41. package/{components → src/lib/components}/chapter/Citations.svelte +34 -33
  42. package/{components → src/lib/components}/chapter/Code.svelte +63 -59
  43. package/{components → src/lib/components}/chapter/Comment.svelte +30 -18
  44. package/{components → src/lib/components}/chapter/Definition.svelte +23 -17
  45. package/{components → src/lib/components}/chapter/Embed.svelte +97 -77
  46. package/src/lib/components/chapter/ErrorMessage.svelte +12 -0
  47. package/{components → src/lib/components}/chapter/ExtendedPrism.js +0 -0
  48. package/{components → src/lib/components}/chapter/Figure.svelte +34 -26
  49. package/{components → src/lib/components}/chapter/Footnote.svelte +32 -20
  50. package/{components → src/lib/components}/chapter/Format.svelte +39 -34
  51. package/{components → src/lib/components}/chapter/InlineCode.svelte +9 -5
  52. package/{components → src/lib/components}/chapter/Label.svelte +23 -14
  53. package/{components → src/lib/components}/chapter/Link.svelte +27 -21
  54. package/{components → src/lib/components}/chapter/List.svelte +5 -3
  55. package/{components → src/lib/components}/chapter/Marginal.svelte +54 -41
  56. package/{components → src/lib/components}/chapter/Paragraph.svelte +25 -20
  57. package/{components → src/lib/components}/chapter/Positioned.svelte +4 -1
  58. package/{components → src/lib/components}/chapter/Problem.svelte +0 -0
  59. package/src/lib/components/chapter/Python.svelte +144 -0
  60. package/{components → src/lib/components}/chapter/Quote.svelte +9 -5
  61. package/{components → src/lib/components}/chapter/Rule.svelte +4 -1
  62. package/{components → src/lib/components}/chapter/Table.svelte +11 -7
  63. package/src/lib/components/chapter/Text.svelte +109 -0
  64. package/src/lib/components/editor/BookishEditor.svelte +1101 -0
  65. package/src/lib/components/editor/CalloutEditor.svelte +14 -0
  66. package/{components → src/lib/components}/editor/CaptionedCodeEditor.svelte +10 -6
  67. package/src/lib/components/editor/CaretContext.ts +55 -0
  68. package/{components/editor/CaretState.d.ts → src/lib/components/editor/CaretState.ts} +6 -7
  69. package/{components/editor/CaretUtilities.d.ts → src/lib/components/editor/CaretUtilities.ts} +1 -0
  70. package/{components → src/lib/components}/editor/CaretView.svelte +25 -20
  71. package/src/lib/components/editor/CitationsEditor.svelte +64 -0
  72. package/{components/editor/Clipboard.d.ts → src/lib/components/editor/Clipboard.ts} +2 -1
  73. package/{components/editor/Command.d.ts → src/lib/components/editor/Command.ts} +8 -2
  74. package/{components/editor/Commands.js → src/lib/components/editor/Commands.ts} +730 -315
  75. package/src/lib/components/editor/ConfirmButton.svelte +51 -0
  76. package/src/lib/components/editor/DefinitionEditor.svelte +44 -0
  77. package/src/lib/components/editor/EmbedEditor.svelte +152 -0
  78. package/{components → src/lib/components}/editor/Icon.svelte +2 -1
  79. package/{components → src/lib/components}/editor/ImageChooser.svelte +24 -19
  80. package/src/lib/components/editor/InlineCodeEditor.svelte +16 -0
  81. package/{components → src/lib/components}/editor/LabelEditor.svelte +14 -9
  82. package/{components → src/lib/components}/editor/LanguageEditor.svelte +8 -5
  83. package/src/lib/components/editor/LinkEditor.svelte +110 -0
  84. package/{components → src/lib/components}/editor/Note.svelte +0 -0
  85. package/{components → src/lib/components}/editor/Permissions.svelte +43 -36
  86. package/src/lib/components/editor/PositionEditor.svelte +21 -0
  87. package/src/lib/components/editor/QuoteEditor.svelte +14 -0
  88. package/{components → src/lib/components}/editor/Switch.svelte +14 -11
  89. package/src/lib/components/editor/TableEditor.svelte +14 -0
  90. package/{components → src/lib/components}/editor/TextEditor.svelte +101 -89
  91. package/src/lib/components/editor/Toggle.svelte +47 -0
  92. package/src/lib/components/editor/Toolbar.svelte +297 -0
  93. package/{components → src/lib/components}/editor/ToolbarGroup.svelte +5 -3
  94. package/{components → src/lib/components}/editor/ToolbarSpacer.svelte +0 -0
  95. package/src/lib/components/editor/URLEditor.svelte +15 -0
  96. package/{components/editor/UndoState.d.ts → src/lib/components/editor/UndoState.ts} +3 -2
  97. package/{components → src/lib/components}/editor/icons/annotate.svg +0 -0
  98. package/{components → src/lib/components}/editor/icons/block.svg +0 -0
  99. package/{components → src/lib/components}/editor/icons/bold.svg +0 -0
  100. package/{components → src/lib/components}/editor/icons/bullets.svg +0 -0
  101. package/{components → src/lib/components}/editor/icons/callout.svg +0 -0
  102. package/{components → src/lib/components}/editor/icons/citation.svg +0 -0
  103. package/{components → src/lib/components}/editor/icons/clear.svg +0 -0
  104. package/{components → src/lib/components}/editor/icons/clipboard.svg +0 -0
  105. package/{components → src/lib/components}/editor/icons/code.svg +0 -0
  106. package/{components → src/lib/components}/editor/icons/columnafter.svg +0 -0
  107. package/{components → src/lib/components}/editor/icons/columnbefore.svg +0 -0
  108. package/{components → src/lib/components}/editor/icons/comment.svg +0 -0
  109. package/{components → src/lib/components}/editor/icons/copy.svg +0 -0
  110. package/{components → src/lib/components}/editor/icons/cut.svg +0 -0
  111. package/{components → src/lib/components}/editor/icons/define.svg +0 -0
  112. package/{components → src/lib/components}/editor/icons/deletecolumn.svg +0 -0
  113. package/{components → src/lib/components}/editor/icons/deleterow.svg +0 -0
  114. package/{components → src/lib/components}/editor/icons/footnote.svg +0 -0
  115. package/{components → src/lib/components}/editor/icons/header1.svg +0 -0
  116. package/{components → src/lib/components}/editor/icons/header2.svg +0 -0
  117. package/{components → src/lib/components}/editor/icons/header3.svg +0 -0
  118. package/{components → src/lib/components}/editor/icons/home.svg +0 -0
  119. package/{components → src/lib/components}/editor/icons/indent.svg +0 -0
  120. package/{components → src/lib/components}/editor/icons/italic.svg +0 -0
  121. package/{components → src/lib/components}/editor/icons/label.svg +0 -0
  122. package/{components → src/lib/components}/editor/icons/left.svg +0 -0
  123. package/{components → src/lib/components}/editor/icons/level.svg +0 -0
  124. package/{components → src/lib/components}/editor/icons/link.svg +0 -0
  125. package/{components → src/lib/components}/editor/icons/list.svg +0 -0
  126. package/{components → src/lib/components}/editor/icons/media.svg +0 -0
  127. package/{components → src/lib/components}/editor/icons/middle.svg +0 -0
  128. package/{components → src/lib/components}/editor/icons/numbers.svg +0 -0
  129. package/{components → src/lib/components}/editor/icons/paragraph.svg +0 -0
  130. package/{components → src/lib/components}/editor/icons/paste.svg +0 -0
  131. package/{components → src/lib/components}/editor/icons/quote.svg +0 -0
  132. package/{components → src/lib/components}/editor/icons/redo.svg +0 -0
  133. package/{components → src/lib/components}/editor/icons/right.svg +0 -0
  134. package/{components → src/lib/components}/editor/icons/rowabove.svg +0 -0
  135. package/{components → src/lib/components}/editor/icons/rowbelow.svg +0 -0
  136. package/{components → src/lib/components}/editor/icons/rule.svg +0 -0
  137. package/{components → src/lib/components}/editor/icons/sub.svg +0 -0
  138. package/{components → src/lib/components}/editor/icons/super.svg +0 -0
  139. package/{components → src/lib/components}/editor/icons/table.svg +0 -0
  140. package/{components → src/lib/components}/editor/icons/text.svg +0 -0
  141. package/{components → src/lib/components}/editor/icons/time.svg +0 -0
  142. package/{components → src/lib/components}/editor/icons/undo.svg +0 -0
  143. package/{components → src/lib/components}/editor/icons/unindent.svg +0 -0
  144. package/{components → src/lib/components}/editor/icons/unlink.svg +0 -0
  145. package/{components → src/lib/components}/page/Acknowledgements.svelte +19 -10
  146. package/src/lib/components/page/Authors.svelte +92 -0
  147. package/src/lib/components/page/BookLoader.svelte +77 -0
  148. package/src/lib/components/page/BulkReferenceEditor.svelte +86 -0
  149. package/src/lib/components/page/Chapter.svelte +449 -0
  150. package/src/lib/components/page/ChapterContext.ts +13 -0
  151. package/{components → src/lib/components}/page/ChapterNumber.svelte +0 -0
  152. package/{components → src/lib/components}/page/ChapterTitle.svelte +4 -2
  153. package/src/lib/components/page/Contexts.ts +176 -0
  154. package/{components → src/lib/components}/page/DefinitionView.svelte +52 -37
  155. package/{components → src/lib/components}/page/Description.svelte +15 -7
  156. package/src/lib/components/page/Edition.svelte +189 -0
  157. package/src/lib/components/page/EditionLoader.svelte +123 -0
  158. package/{components → src/lib/components}/page/Editions.svelte +22 -18
  159. package/{components → src/lib/components}/page/Glossary.svelte +33 -28
  160. package/{components → src/lib/components}/page/Header.svelte +59 -52
  161. package/{components → src/lib/components}/page/Index.svelte +48 -41
  162. package/{components → src/lib/components}/page/Instructions.svelte +2 -1
  163. package/{components → src/lib/components}/page/License.svelte +17 -9
  164. package/{components → src/lib/components}/page/Loading.svelte +0 -0
  165. package/{components → src/lib/components}/page/Media.svelte +44 -27
  166. package/{components → src/lib/components}/page/MediaPreview.svelte +3 -2
  167. package/{components → src/lib/components}/page/Muted.svelte +0 -0
  168. package/{components → src/lib/components}/page/Outline.svelte +140 -110
  169. package/src/lib/components/page/Page.svelte +94 -0
  170. package/{components → src/lib/components}/page/PageHeader.svelte +2 -1
  171. package/{components → src/lib/components}/page/PageParagraph.svelte +0 -0
  172. package/src/lib/components/page/PossibleChapter.svelte +16 -0
  173. package/src/lib/components/page/PossibleReference.svelte +14 -0
  174. package/{components → src/lib/components}/page/Print.svelte +5 -3
  175. package/{components → src/lib/components}/page/Publish.svelte +59 -52
  176. package/{components → src/lib/components}/page/Reference.svelte +39 -30
  177. package/{components → src/lib/components}/page/References.svelte +18 -14
  178. package/{components → src/lib/components}/page/Rows.svelte +0 -0
  179. package/src/lib/components/page/Search.svelte +153 -0
  180. package/{components → src/lib/components}/page/Status.svelte +5 -3
  181. package/{components → src/lib/components}/page/SubdomainEditor.svelte +16 -13
  182. package/{components → src/lib/components}/page/TableOfContents.svelte +79 -68
  183. package/src/lib/components/page/TableOfContentsImage.svelte +22 -0
  184. package/{components → src/lib/components}/page/TableOfContentsRow.svelte +34 -24
  185. package/{components → src/lib/components}/page/ThemeEditor.svelte +44 -33
  186. package/{components → src/lib/components}/page/ThemeEditorPreview.svelte +21 -12
  187. package/src/lib/components/page/ThemeSetEditor.svelte +21 -0
  188. package/{components → src/lib/components}/page/ThemeVariableEditor.svelte +18 -14
  189. package/{components → src/lib/components}/page/Title.svelte +0 -0
  190. package/{components → src/lib/components}/page/Unknown.svelte +10 -8
  191. package/{components/page/margins.js → src/lib/components/page/margins.ts} +79 -46
  192. package/{index.js → src/lib/index.js} +0 -0
  193. package/src/lib/models/CRUD.ts +469 -0
  194. package/{models/Firebase.js → src/lib/models/Firebase.ts} +26 -16
  195. package/src/lib/models/book/Book.ts +283 -0
  196. package/src/lib/models/book/BookMedia.ts +182 -0
  197. package/src/lib/models/book/BookSaveStatus.ts +8 -0
  198. package/src/lib/models/book/Chapter.ts +462 -0
  199. package/{models/book/ChapterID.js → src/lib/models/book/ChapterID.ts} +1 -0
  200. package/src/lib/models/book/Definition.ts +2 -0
  201. package/src/lib/models/book/Edition.ts +1216 -0
  202. package/src/lib/models/book/Reference.ts +171 -0
  203. package/{models/book/Schema.js → src/lib/models/book/Schema.ts} +1 -0
  204. package/{models/book/Theme.js → src/lib/models/book/Theme.ts} +110 -6
  205. package/{models/book/ThemeColors.d.ts → src/lib/models/book/ThemeColors.ts} +6 -0
  206. package/{models/book/Words.js → src/lib/models/book/Words.ts} +1 -0
  207. package/{models/chapter/AtomNode.js → src/lib/models/chapter/AtomNode.ts} +30 -10
  208. package/{models/chapter/BlockNode.js → src/lib/models/chapter/BlockNode.ts} +80 -47
  209. package/src/lib/models/chapter/BlocksNode.test.ts +867 -0
  210. package/{models/chapter/BlocksNode.js → src/lib/models/chapter/BlocksNode.ts} +571 -359
  211. package/{models/chapter/Bookkeeping.d.ts → src/lib/models/chapter/Bookkeeping.ts} +0 -0
  212. package/src/lib/models/chapter/CalloutNode.ts +79 -0
  213. package/{models/chapter/Caret.js → src/lib/models/chapter/Caret.ts} +50 -26
  214. package/src/lib/models/chapter/ChapterNode.ts +169 -0
  215. package/{models/chapter/CitationsNode.js → src/lib/models/chapter/CitationsNode.ts} +17 -10
  216. package/{models/chapter/CodeNode.js → src/lib/models/chapter/CodeNode.ts} +125 -62
  217. package/src/lib/models/chapter/CommentNode.ts +61 -0
  218. package/{models/chapter/DefinitionNode.js → src/lib/models/chapter/DefinitionNode.ts} +14 -8
  219. package/src/lib/models/chapter/Edit.ts +6 -0
  220. package/src/lib/models/chapter/EmbedNode.ts +257 -0
  221. package/{models/chapter/ErrorNode.js → src/lib/models/chapter/ErrorNode.ts} +15 -8
  222. package/src/lib/models/chapter/FootnoteNode.ts +59 -0
  223. package/src/lib/models/chapter/FormatNode.test.ts +137 -0
  224. package/{models/chapter/FormatNode.js → src/lib/models/chapter/FormatNode.ts} +443 -262
  225. package/{models/chapter/InlineCodeNode.js → src/lib/models/chapter/InlineCodeNode.ts} +17 -9
  226. package/{models/chapter/LabelNode.js → src/lib/models/chapter/LabelNode.ts} +26 -10
  227. package/{models/chapter/LinkNode.js → src/lib/models/chapter/LinkNode.ts} +12 -7
  228. package/{models/chapter/ListNode.test.js → src/lib/models/chapter/ListNode.test.ts} +57 -20
  229. package/{models/chapter/ListNode.js → src/lib/models/chapter/ListNode.ts} +277 -200
  230. package/src/lib/models/chapter/MetadataNode.ts +44 -0
  231. package/{models → src/lib/models}/chapter/Node.test.js +0 -0
  232. package/{models/chapter/Node.js → src/lib/models/chapter/Node.ts} +155 -71
  233. package/src/lib/models/chapter/ParagraphNode.test.ts +54 -0
  234. package/{models/chapter/ParagraphNode.js → src/lib/models/chapter/ParagraphNode.ts} +95 -58
  235. package/{models/chapter/Parser.test.js → src/lib/models/chapter/Parser.test.ts} +7 -0
  236. package/{models/chapter/Parser.js → src/lib/models/chapter/Parser.ts} +369 -184
  237. package/{models/chapter/Position.d.ts → src/lib/models/chapter/Position.ts} +0 -0
  238. package/src/lib/models/chapter/QuoteNode.ts +135 -0
  239. package/{models/chapter/RootNode.d.ts → src/lib/models/chapter/RootNode.ts} +2 -0
  240. package/{models/chapter/RuleNode.js → src/lib/models/chapter/RuleNode.ts} +9 -6
  241. package/{models/chapter/TableNode.test.js → src/lib/models/chapter/TableNode.test.ts} +27 -10
  242. package/{models/chapter/TableNode.js → src/lib/models/chapter/TableNode.ts} +141 -82
  243. package/{models/chapter/TextNode.test.js → src/lib/models/chapter/TextNode.test.ts} +2 -0
  244. package/{models/chapter/TextNode.js → src/lib/models/chapter/TextNode.ts} +117 -65
  245. package/{util/getSubdomain.js → src/lib/util/getSubdomain.ts} +14 -8
  246. package/{util/isMobile.js → src/lib/util/isMobile.ts} +1 -0
  247. package/{util/mineReference.js → src/lib/util/mineReference.ts} +45 -25
  248. package/{util/scrollToEyeLevel.js → src/lib/util/scrollToEyeLevel.ts} +4 -2
  249. package/src/params/edition.ts +3 -0
  250. package/src/routes/+error.svelte +12 -0
  251. package/src/routes/+layout.svelte +241 -0
  252. package/src/routes/+page.svelte +43 -0
  253. package/src/routes/Footer.svelte +0 -0
  254. package/src/routes/Header.svelte +112 -0
  255. package/src/routes/[bookid]/+layout.svelte +5 -0
  256. package/src/routes/[bookid]/[[editionid=edition]]/+error.svelte +14 -0
  257. package/src/routes/[bookid]/[[editionid=edition]]/+layout.svelte +7 -0
  258. package/src/routes/[bookid]/[[editionid=edition]]/+page.svelte +5 -0
  259. package/src/routes/[bookid]/[[editionid=edition]]/[chapterid]/+page.svelte +5 -0
  260. package/src/routes/[bookid]/[[editionid=edition]]/glossary/+page.svelte +5 -0
  261. package/src/routes/[bookid]/[[editionid=edition]]/index/[[letter]]/+page.svelte +5 -0
  262. package/src/routes/[bookid]/[[editionid=edition]]/media/+page.svelte +5 -0
  263. package/src/routes/[bookid]/[[editionid=edition]]/print/+page.svelte +5 -0
  264. package/src/routes/[bookid]/[[editionid=edition]]/references/+page.svelte +5 -0
  265. package/src/routes/[bookid]/[[editionid=edition]]/search/+page.svelte +5 -0
  266. package/src/routes/[bookid]/editions/+page.svelte +20 -0
  267. package/src/routes/about/+page.svelte +102 -0
  268. package/src/routes/confirm/+page.svelte +62 -0
  269. package/src/routes/email/+page.svelte +99 -0
  270. package/src/routes/login/+page.svelte +66 -0
  271. package/src/routes/read/+page.svelte +38 -0
  272. package/src/routes/write/+error.svelte +10 -0
  273. package/src/routes/write/+layout.svelte +11 -0
  274. package/src/routes/write/+page.svelte +114 -0
  275. package/src/routes/write/[bookid]/+layout.svelte +5 -0
  276. package/src/routes/write/[bookid]/[[editionid=edition]]/+layout.svelte +7 -0
  277. package/src/routes/write/[bookid]/[[editionid=edition]]/+page.svelte +5 -0
  278. package/src/routes/write/[bookid]/[[editionid=edition]]/[chapterid]/+page.svelte +5 -0
  279. package/src/routes/write/[bookid]/[[editionid=edition]]/glossary/+page.svelte +5 -0
  280. package/src/routes/write/[bookid]/[[editionid=edition]]/index/[[letter]]/+page.svelte +5 -0
  281. package/src/routes/write/[bookid]/[[editionid=edition]]/media/+page.svelte +5 -0
  282. package/src/routes/write/[bookid]/[[editionid=edition]]/print/+page.svelte +5 -0
  283. package/src/routes/write/[bookid]/[[editionid=edition]]/references/+page.svelte +5 -0
  284. package/src/routes/write/[bookid]/[[editionid=edition]]/search/+page.svelte +5 -0
  285. package/src/routes/write/[bookid]/[[editionid=edition]]/theme/+page.svelte +5 -0
  286. package/src/routes/write/[bookid]/[[editionid=edition]]/unknown/+page.svelte +5 -0
  287. package/src/routes/write/[bookid]/editions/+page.svelte +20 -0
  288. package/src/vite-env.d.ts +1 -0
  289. package/static/icons/favicon.png +0 -0
  290. package/static/icons/icon.png +0 -0
  291. package/static/icons/ios-icon.png +0 -0
  292. package/storage.rules +9 -0
  293. package/svelte.config.js +19 -0
  294. package/tsconfig.json +18 -0
  295. package/tsconfig.node.json +9 -0
  296. package/vite.config.ts +8 -0
  297. package/vite.reader.config.ts +32 -0
  298. package/components/Auth.svelte +0 -55
  299. package/components/Auth.svelte.d.ts +0 -16
  300. package/components/Authentication.js +0 -1
  301. package/components/BookPreview.svelte.d.ts +0 -18
  302. package/components/External.svelte.d.ts +0 -18
  303. package/components/Link.svelte +0 -51
  304. package/components/Link.svelte.d.ts +0 -18
  305. package/components/app/BookList.svelte.d.ts +0 -18
  306. package/components/app/Button.svelte.d.ts +0 -22
  307. package/components/app/Feedback.svelte.d.ts +0 -18
  308. package/components/app/Head.svelte.d.ts +0 -18
  309. package/components/app/Large.svelte.d.ts +0 -27
  310. package/components/app/Lead.svelte.d.ts +0 -27
  311. package/components/app/Link.svelte.d.ts +0 -20
  312. package/components/app/Options.svelte.d.ts +0 -19
  313. package/components/app/Paragraph.svelte.d.ts +0 -18
  314. package/components/app/Section.svelte.d.ts +0 -27
  315. package/components/app/Table.svelte.d.ts +0 -27
  316. package/components/app/TextInput.svelte.d.ts +0 -22
  317. package/components/chapter/Atom.svelte.d.ts +0 -19
  318. package/components/chapter/Block.svelte +0 -37
  319. package/components/chapter/Block.svelte.d.ts +0 -17
  320. package/components/chapter/Callout.svelte.d.ts +0 -17
  321. package/components/chapter/CaptionedCode.svelte.d.ts +0 -17
  322. package/components/chapter/ChapterBody.svelte.d.ts +0 -19
  323. package/components/chapter/Citations.svelte.d.ts +0 -17
  324. package/components/chapter/Code.svelte.d.ts +0 -22
  325. package/components/chapter/Comment.svelte.d.ts +0 -17
  326. package/components/chapter/Definition.svelte.d.ts +0 -17
  327. package/components/chapter/Embed.svelte.d.ts +0 -20
  328. package/components/chapter/ErrorMessage.svelte +0 -9
  329. package/components/chapter/ErrorMessage.svelte.d.ts +0 -17
  330. package/components/chapter/ExtendedPrism.d.ts +0 -2
  331. package/components/chapter/Figure.svelte.d.ts +0 -24
  332. package/components/chapter/Footnote.svelte.d.ts +0 -19
  333. package/components/chapter/Format.svelte.d.ts +0 -19
  334. package/components/chapter/InlineCode.svelte.d.ts +0 -17
  335. package/components/chapter/Label.svelte.d.ts +0 -17
  336. package/components/chapter/Link.svelte.d.ts +0 -17
  337. package/components/chapter/List.svelte.d.ts +0 -17
  338. package/components/chapter/Marginal.svelte.d.ts +0 -22
  339. package/components/chapter/Paragraph.svelte.d.ts +0 -18
  340. package/components/chapter/Positioned.svelte.d.ts +0 -19
  341. package/components/chapter/Problem.svelte.d.ts +0 -27
  342. package/components/chapter/Python.svelte +0 -128
  343. package/components/chapter/Python.svelte.d.ts +0 -18
  344. package/components/chapter/Quote.svelte.d.ts +0 -17
  345. package/components/chapter/Rule.svelte.d.ts +0 -17
  346. package/components/chapter/Table.svelte.d.ts +0 -17
  347. package/components/chapter/Text.svelte +0 -87
  348. package/components/chapter/Text.svelte.d.ts +0 -18
  349. package/components/editor/BookishEditor.svelte +0 -884
  350. package/components/editor/BookishEditor.svelte.d.ts +0 -25
  351. package/components/editor/CalloutEditor.svelte +0 -10
  352. package/components/editor/CalloutEditor.svelte.d.ts +0 -17
  353. package/components/editor/CaptionedCodeEditor.svelte.d.ts +0 -17
  354. package/components/editor/CaretContext.d.ts +0 -50
  355. package/components/editor/CaretContext.js +0 -1
  356. package/components/editor/CaretState.js +0 -1
  357. package/components/editor/CaretUtilities.js +0 -1
  358. package/components/editor/CaretView.svelte.d.ts +0 -25
  359. package/components/editor/CitationsEditor.svelte +0 -53
  360. package/components/editor/CitationsEditor.svelte.d.ts +0 -17
  361. package/components/editor/Clipboard.js +0 -1
  362. package/components/editor/Command.js +0 -1
  363. package/components/editor/Commands.d.ts +0 -3
  364. package/components/editor/ConfirmButton.svelte +0 -49
  365. package/components/editor/ConfirmButton.svelte.d.ts +0 -19
  366. package/components/editor/DefinitionEditor.svelte +0 -36
  367. package/components/editor/DefinitionEditor.svelte.d.ts +0 -17
  368. package/components/editor/EmbedEditor.svelte +0 -137
  369. package/components/editor/EmbedEditor.svelte.d.ts +0 -17
  370. package/components/editor/Icon.svelte.d.ts +0 -16
  371. package/components/editor/ImageChooser.svelte.d.ts +0 -18
  372. package/components/editor/InlineCodeEditor.svelte +0 -12
  373. package/components/editor/InlineCodeEditor.svelte.d.ts +0 -17
  374. package/components/editor/LabelEditor.svelte.d.ts +0 -17
  375. package/components/editor/LanguageEditor.svelte.d.ts +0 -17
  376. package/components/editor/LinkEditor.svelte +0 -100
  377. package/components/editor/LinkEditor.svelte.d.ts +0 -17
  378. package/components/editor/Note.svelte.d.ts +0 -27
  379. package/components/editor/Permissions.svelte.d.ts +0 -20
  380. package/components/editor/PositionEditor.svelte +0 -17
  381. package/components/editor/PositionEditor.svelte.d.ts +0 -18
  382. package/components/editor/QuoteEditor.svelte +0 -10
  383. package/components/editor/QuoteEditor.svelte.d.ts +0 -17
  384. package/components/editor/Switch.svelte.d.ts +0 -20
  385. package/components/editor/TableEditor.svelte +0 -10
  386. package/components/editor/TableEditor.svelte.d.ts +0 -17
  387. package/components/editor/TextEditor.svelte.d.ts +0 -24
  388. package/components/editor/Toggle.svelte +0 -41
  389. package/components/editor/Toggle.svelte.d.ts +0 -19
  390. package/components/editor/Toolbar.svelte +0 -249
  391. package/components/editor/Toolbar.svelte.d.ts +0 -17
  392. package/components/editor/ToolbarGroup.svelte.d.ts +0 -18
  393. package/components/editor/ToolbarSpacer.svelte.d.ts +0 -23
  394. package/components/editor/URLEditor.svelte +0 -13
  395. package/components/editor/URLEditor.svelte.d.ts +0 -18
  396. package/components/editor/UndoState.js +0 -1
  397. package/components/page/Acknowledgements.svelte.d.ts +0 -14
  398. package/components/page/Authors.svelte +0 -85
  399. package/components/page/Authors.svelte.d.ts +0 -21
  400. package/components/page/BookLoader.svelte +0 -59
  401. package/components/page/BookLoader.svelte.d.ts +0 -16
  402. package/components/page/BulkReferenceEditor.svelte +0 -63
  403. package/components/page/BulkReferenceEditor.svelte.d.ts +0 -14
  404. package/components/page/Chapter.svelte +0 -392
  405. package/components/page/Chapter.svelte.d.ts +0 -18
  406. package/components/page/ChapterContext.d.ts +0 -10
  407. package/components/page/ChapterContext.js +0 -1
  408. package/components/page/ChapterNumber.svelte.d.ts +0 -27
  409. package/components/page/ChapterTitle.svelte.d.ts +0 -18
  410. package/components/page/Contexts.d.ts +0 -47
  411. package/components/page/Contexts.js +0 -133
  412. package/components/page/DefinitionView.svelte.d.ts +0 -18
  413. package/components/page/Description.svelte.d.ts +0 -14
  414. package/components/page/Edition.svelte +0 -161
  415. package/components/page/Edition.svelte.d.ts +0 -20
  416. package/components/page/EditionLoader.svelte +0 -99
  417. package/components/page/EditionLoader.svelte.d.ts +0 -18
  418. package/components/page/Editions.svelte.d.ts +0 -14
  419. package/components/page/Glossary.svelte.d.ts +0 -14
  420. package/components/page/Header.svelte.d.ts +0 -29
  421. package/components/page/Index.svelte.d.ts +0 -14
  422. package/components/page/Instructions.svelte.d.ts +0 -18
  423. package/components/page/License.svelte.d.ts +0 -14
  424. package/components/page/Loading.svelte.d.ts +0 -23
  425. package/components/page/Media.svelte.d.ts +0 -14
  426. package/components/page/MediaPreview.svelte.d.ts +0 -19
  427. package/components/page/Muted.svelte.d.ts +0 -27
  428. package/components/page/Outline.svelte.d.ts +0 -19
  429. package/components/page/Page.svelte +0 -84
  430. package/components/page/Page.svelte.d.ts +0 -19
  431. package/components/page/PageHeader.svelte.d.ts +0 -18
  432. package/components/page/PageParagraph.svelte.d.ts +0 -27
  433. package/components/page/PossibleChapter.svelte +0 -14
  434. package/components/page/PossibleChapter.svelte.d.ts +0 -14
  435. package/components/page/PossibleReference.svelte +0 -11
  436. package/components/page/PossibleReference.svelte.d.ts +0 -18
  437. package/components/page/Print.svelte.d.ts +0 -14
  438. package/components/page/Publish.svelte.d.ts +0 -14
  439. package/components/page/Reference.svelte.d.ts +0 -17
  440. package/components/page/References.svelte.d.ts +0 -14
  441. package/components/page/Rows.svelte.d.ts +0 -27
  442. package/components/page/Search.svelte +0 -133
  443. package/components/page/Search.svelte.d.ts +0 -14
  444. package/components/page/Status.svelte.d.ts +0 -14
  445. package/components/page/SubdomainEditor.svelte.d.ts +0 -14
  446. package/components/page/TableOfContents.svelte.d.ts +0 -14
  447. package/components/page/TableOfContentsImage.svelte +0 -18
  448. package/components/page/TableOfContentsImage.svelte.d.ts +0 -16
  449. package/components/page/TableOfContentsRow.svelte.d.ts +0 -24
  450. package/components/page/ThemeEditor.svelte.d.ts +0 -14
  451. package/components/page/ThemeEditorPreview.svelte.d.ts +0 -17
  452. package/components/page/ThemeSetEditor.svelte +0 -19
  453. package/components/page/ThemeSetEditor.svelte.d.ts +0 -18
  454. package/components/page/ThemeVariableEditor.svelte.d.ts +0 -18
  455. package/components/page/Title.svelte.d.ts +0 -27
  456. package/components/page/Unknown.svelte.d.ts +0 -16
  457. package/components/page/margins.d.ts +0 -2
  458. package/index.d.ts +0 -15
  459. package/models/CRUD.d.ts +0 -27
  460. package/models/CRUD.js +0 -262
  461. package/models/Firebase.d.ts +0 -5
  462. package/models/book/Book.d.ts +0 -61
  463. package/models/book/Book.js +0 -135
  464. package/models/book/BookMedia.d.ts +0 -23
  465. package/models/book/BookMedia.js +0 -108
  466. package/models/book/BookSaveStatus.d.ts +0 -7
  467. package/models/book/BookSaveStatus.js +0 -8
  468. package/models/book/Chapter.d.ts +0 -81
  469. package/models/book/Chapter.js +0 -212
  470. package/models/book/ChapterID.d.ts +0 -10
  471. package/models/book/Definition.d.ts +0 -6
  472. package/models/book/Definition.js +0 -1
  473. package/models/book/Edition.d.ts +0 -139
  474. package/models/book/Edition.js +0 -620
  475. package/models/book/Reference.d.ts +0 -24
  476. package/models/book/Reference.js +0 -78
  477. package/models/book/Schema.d.ts +0 -174
  478. package/models/book/Theme.d.ts +0 -113
  479. package/models/book/ThemeColors.js +0 -1
  480. package/models/book/Words.d.ts +0 -2
  481. package/models/chapter/AtomNode.d.ts +0 -18
  482. package/models/chapter/BlockNode.d.ts +0 -20
  483. package/models/chapter/BlocksNode.d.ts +0 -50
  484. package/models/chapter/BlocksNode.test.d.ts +0 -1
  485. package/models/chapter/BlocksNode.test.js +0 -568
  486. package/models/chapter/Bookkeeping.js +0 -1
  487. package/models/chapter/CalloutNode.d.ts +0 -17
  488. package/models/chapter/CalloutNode.js +0 -58
  489. package/models/chapter/Caret.d.ts +0 -23
  490. package/models/chapter/ChapterNode.d.ts +0 -34
  491. package/models/chapter/ChapterNode.js +0 -117
  492. package/models/chapter/CitationsNode.d.ts +0 -16
  493. package/models/chapter/CodeNode.d.ts +0 -35
  494. package/models/chapter/CommentNode.d.ts +0 -18
  495. package/models/chapter/CommentNode.js +0 -48
  496. package/models/chapter/DefinitionNode.d.ts +0 -12
  497. package/models/chapter/Edit.d.ts +0 -7
  498. package/models/chapter/Edit.js +0 -1
  499. package/models/chapter/EmbedNode.d.ts +0 -45
  500. package/models/chapter/EmbedNode.js +0 -168
  501. package/models/chapter/ErrorNode.d.ts +0 -17
  502. package/models/chapter/FootnoteNode.d.ts +0 -18
  503. package/models/chapter/FootnoteNode.js +0 -47
  504. package/models/chapter/FormatNode.d.ts +0 -60
  505. package/models/chapter/FormatNode.test.d.ts +0 -1
  506. package/models/chapter/FormatNode.test.js +0 -96
  507. package/models/chapter/InlineCodeNode.d.ts +0 -12
  508. package/models/chapter/LabelNode.d.ts +0 -17
  509. package/models/chapter/LinkNode.d.ts +0 -12
  510. package/models/chapter/ListNode.d.ts +0 -51
  511. package/models/chapter/ListNode.test.d.ts +0 -1
  512. package/models/chapter/MetadataNode.d.ts +0 -17
  513. package/models/chapter/MetadataNode.js +0 -32
  514. package/models/chapter/Node.d.ts +0 -38
  515. package/models/chapter/Node.test.d.ts +0 -1
  516. package/models/chapter/ParagraphNode.d.ts +0 -33
  517. package/models/chapter/ParagraphNode.test.d.ts +0 -1
  518. package/models/chapter/ParagraphNode.test.js +0 -30
  519. package/models/chapter/Parser.d.ts +0 -75
  520. package/models/chapter/Parser.test.d.ts +0 -1
  521. package/models/chapter/Position.js +0 -1
  522. package/models/chapter/QuoteNode.d.ts +0 -25
  523. package/models/chapter/QuoteNode.js +0 -99
  524. package/models/chapter/RootNode.js +0 -1
  525. package/models/chapter/RuleNode.d.ts +0 -15
  526. package/models/chapter/TableNode.d.ts +0 -37
  527. package/models/chapter/TableNode.test.d.ts +0 -1
  528. package/models/chapter/TextNode.d.ts +0 -36
  529. package/models/chapter/TextNode.test.d.ts +0 -1
  530. package/util/getSubdomain.d.ts +0 -3
  531. package/util/isMobile.d.ts +0 -2
  532. package/util/mineReference.d.ts +0 -4
  533. package/util/scrollToEyeLevel.d.ts +0 -2
@@ -1,22 +1,30 @@
1
- import CalloutNode from '../../models/chapter/CalloutNode';
2
- import CitationsNode from '../../models/chapter/CitationsNode';
3
- import CodeNode from '../../models/chapter/CodeNode';
4
- import CommentNode from '../../models/chapter/CommentNode';
5
- import DefinitionNode from '../../models/chapter/DefinitionNode';
6
- import EmbedNode from '../../models/chapter/EmbedNode';
7
- import FootnoteNode from '../../models/chapter/FootnoteNode';
8
- import FormatNode from '../../models/chapter/FormatNode';
9
- import InlineCodeNode from '../../models/chapter/InlineCodeNode';
10
- import LabelNode from '../../models/chapter/LabelNode';
11
- import LinkNode from '../../models/chapter/LinkNode';
12
- import ListNode from '../../models/chapter/ListNode';
13
- import ParagraphNode from '../../models/chapter/ParagraphNode';
14
- import QuoteNode from '../../models/chapter/QuoteNode';
15
- import RuleNode from '../../models/chapter/RuleNode';
16
- import TableNode from '../../models/chapter/TableNode';
17
- import TextNode from '../../models/chapter/TextNode';
18
- import AtomNode from '../../models/chapter/AtomNode';
19
- import BlocksNode from '../../models/chapter/BlocksNode';
1
+ import CalloutNode from '$lib/models/chapter/CalloutNode';
2
+ import type Caret from '$lib/models/chapter/Caret';
3
+ import CitationsNode from '$lib/models/chapter/CitationsNode';
4
+ import CodeNode from '$lib/models/chapter/CodeNode';
5
+ import CommentNode from '$lib/models/chapter/CommentNode';
6
+ import DefinitionNode from '$lib/models/chapter/DefinitionNode';
7
+ import EmbedNode from '$lib/models/chapter/EmbedNode';
8
+ import FootnoteNode from '$lib/models/chapter/FootnoteNode';
9
+ import FormatNode from '$lib/models/chapter/FormatNode';
10
+ import InlineCodeNode from '$lib/models/chapter/InlineCodeNode';
11
+ import LabelNode from '$lib/models/chapter/LabelNode';
12
+ import LinkNode from '$lib/models/chapter/LinkNode';
13
+ import ListNode from '$lib/models/chapter/ListNode';
14
+ import ParagraphNode from '$lib/models/chapter/ParagraphNode';
15
+ import QuoteNode from '$lib/models/chapter/QuoteNode';
16
+ import RuleNode from '$lib/models/chapter/RuleNode';
17
+ import TableNode from '$lib/models/chapter/TableNode';
18
+ import TextNode from '$lib/models/chapter/TextNode';
19
+ import AtomNode from '$lib/models/chapter/AtomNode';
20
+ import BlocksNode from '$lib/models/chapter/BlocksNode';
21
+
22
+ import type RootNode from '$lib/models/chapter/RootNode';
23
+ import type Edit from '$lib/models/chapter/Edit';
24
+ import type Node from '$lib/models/chapter/Node';
25
+ import type CaretContext from './CaretContext';
26
+ import type Command from './Command';
27
+
20
28
  import BoldIcon from './icons/bold.svg?raw';
21
29
  import BulletsIcon from './icons/bullets.svg?raw';
22
30
  import CalloutIcon from './icons/callout.svg?raw';
@@ -53,6 +61,7 @@ import SuperscriptIcon from './icons/super.svg?raw';
53
61
  import TableIcon from './icons/table.svg?raw';
54
62
  import UndoIcon from './icons/undo.svg?raw';
55
63
  import UnindentIcon from './icons/unindent.svg?raw';
64
+ import type { PasteContent } from './CaretContext';
56
65
  /**
57
66
  * Icons:
58
67
  * From: https://www.streamlinehq.com/icons/streamline-mini-line
@@ -62,53 +71,93 @@ import UnindentIcon from './icons/unindent.svg?raw';
62
71
  * 48 px
63
72
  * stroke width 1
64
73
  * */
65
- function insertTableRowColumn(context, table, format, row, before) {
74
+
75
+ function insertTableRowColumn(
76
+ context: CaretContext,
77
+ table: TableNode,
78
+ format: FormatNode,
79
+ row: boolean,
80
+ before: boolean
81
+ ): Edit {
66
82
  const location = table.locate(format);
67
- if (location === undefined)
68
- return;
69
- return rootWithNode(context, table, row
70
- ? table.withNewRow(location.row + (before ? 0 : 1))
71
- : table.withNewColumn(location.column + (before ? 0 : 1)), (t) => t.getCell(location.row + (row && !before ? 1 : 0), location.column + (!row && !before ? 1 : 0)).getFirstCaret());
83
+ if (location === undefined) return;
84
+ return rootWithNode(
85
+ context,
86
+ table,
87
+ row
88
+ ? table.withNewRow(location.row + (before ? 0 : 1))
89
+ : table.withNewColumn(location.column + (before ? 0 : 1)),
90
+ (t) =>
91
+ (
92
+ (t as TableNode).getCell(
93
+ location.row + (row && !before ? 1 : 0),
94
+ location.column + (!row && !before ? 1 : 0)
95
+ ) as FormatNode
96
+ ).getFirstCaret()
97
+ );
72
98
  }
73
- function deleteTableRowColumn(context, table, format, row) {
99
+
100
+ function deleteTableRowColumn(
101
+ context: CaretContext,
102
+ table: TableNode,
103
+ format: FormatNode,
104
+ row: boolean
105
+ ): Edit {
74
106
  const location = table.locate(format);
75
- if (location === undefined)
76
- return;
77
- return rootWithNode(context, table, row
78
- ? table.withoutRow(location.row)
79
- : table.withoutColumn(location.column), (t) => {
80
- return (row
81
- ? t.getCell(location.row === table.getRowCount()
82
- ? location.row - 1
83
- : location.row, location.column)
84
- : t.getCell(location.row, location.column === table.getColumnCount()
85
- ? location.column - 1
86
- : location.column))?.getFirstCaret();
87
- });
107
+ if (location === undefined) return;
108
+ return rootWithNode(
109
+ context,
110
+ table,
111
+ row
112
+ ? table.withoutRow(location.row)
113
+ : table.withoutColumn(location.column),
114
+ (t) => {
115
+ return (
116
+ row
117
+ ? (t as TableNode).getCell(
118
+ location.row === table.getRowCount()
119
+ ? location.row - 1
120
+ : location.row,
121
+ location.column
122
+ )
123
+ : (t as TableNode).getCell(
124
+ location.row,
125
+ location.column === table.getColumnCount()
126
+ ? location.column - 1
127
+ : location.column
128
+ )
129
+ )?.getFirstCaret();
130
+ }
131
+ );
88
132
  }
133
+
89
134
  // A helper function that encapsulates boilerplate for replacing a node in a root and updating a caret.
90
- function rootWithNode(context, original, replacement, caret) {
135
+ function rootWithNode<NodeType extends Node>(
136
+ context: CaretContext,
137
+ original: NodeType | undefined,
138
+ replacement: NodeType | undefined,
139
+ caret?: (node: NodeType) => Caret | undefined
140
+ ): Edit | undefined {
91
141
  // If there was no original or replacement, do nothing. Saves commands from having to check.
92
- if (original === undefined || replacement === undefined)
93
- return;
142
+ if (original === undefined || replacement === undefined) return;
94
143
  // Make the new root. Bail on fail.
95
144
  const newRoot = context.root.withNodeReplaced(original, replacement);
96
- if (newRoot === undefined)
97
- return;
145
+ if (newRoot === undefined) return;
98
146
  // Generate a new caret based on the replacement, if there's a generator. Bail on fail.
99
147
  const newCaret = caret?.call(undefined, replacement);
100
- if (caret !== undefined && newCaret === undefined)
101
- return;
148
+ if (caret !== undefined && newCaret === undefined) return;
102
149
  // Return the edit
103
150
  return {
104
151
  root: newRoot,
105
- range: newCaret !== undefined
106
- ? { start: newCaret, end: newCaret }
107
- : context.range,
152
+ range:
153
+ newCaret !== undefined
154
+ ? { start: newCaret, end: newCaret }
155
+ : context.range,
108
156
  };
109
157
  }
158
+
110
159
  // An ordered list of command specifications for keyboard and mouse input.
111
- const commands = [
160
+ const commands: Command[] = [
112
161
  {
113
162
  icon: RowAboveIcon,
114
163
  description: 'insert row above',
@@ -119,10 +168,18 @@ const commands = [
119
168
  shift: false,
120
169
  key: 'ArrowUp',
121
170
  visible: (context) => context.table !== undefined,
122
- active: (context) => context.table !== undefined && context.format !== undefined,
123
- handler: (context) => context.table !== undefined && context.format !== undefined
124
- ? insertTableRowColumn(context, context.table, context.format, true, true)
125
- : undefined,
171
+ active: (context) =>
172
+ context.table !== undefined && context.format !== undefined,
173
+ handler: (context) =>
174
+ context.table !== undefined && context.format !== undefined
175
+ ? insertTableRowColumn(
176
+ context,
177
+ context.table,
178
+ context.format,
179
+ true,
180
+ true
181
+ )
182
+ : undefined,
126
183
  },
127
184
  {
128
185
  icon: RowBelowIcon,
@@ -134,10 +191,18 @@ const commands = [
134
191
  shift: false,
135
192
  key: 'ArrowDown',
136
193
  visible: (context) => context.table !== undefined,
137
- active: (context) => context.table !== undefined && context.format !== undefined,
138
- handler: (context) => context.table !== undefined && context.format !== undefined
139
- ? insertTableRowColumn(context, context.table, context.format, true, false)
140
- : undefined,
194
+ active: (context) =>
195
+ context.table !== undefined && context.format !== undefined,
196
+ handler: (context) =>
197
+ context.table !== undefined && context.format !== undefined
198
+ ? insertTableRowColumn(
199
+ context,
200
+ context.table,
201
+ context.format,
202
+ true,
203
+ false
204
+ )
205
+ : undefined,
141
206
  },
142
207
  {
143
208
  icon: ColumnAfterIcon,
@@ -149,10 +214,18 @@ const commands = [
149
214
  shift: false,
150
215
  key: 'ArrowRight',
151
216
  visible: (context) => context.table !== undefined,
152
- active: (context) => context.table !== undefined && context.format !== undefined,
153
- handler: (context) => context.table !== undefined && context.format !== undefined
154
- ? insertTableRowColumn(context, context.table, context.format, false, false)
155
- : undefined,
217
+ active: (context) =>
218
+ context.table !== undefined && context.format !== undefined,
219
+ handler: (context) =>
220
+ context.table !== undefined && context.format !== undefined
221
+ ? insertTableRowColumn(
222
+ context,
223
+ context.table,
224
+ context.format,
225
+ false,
226
+ false
227
+ )
228
+ : undefined,
156
229
  },
157
230
  {
158
231
  icon: ColumnBeforeIcon,
@@ -164,10 +237,18 @@ const commands = [
164
237
  shift: false,
165
238
  key: 'ArrowLeft',
166
239
  visible: (context) => context.table !== undefined,
167
- active: (context) => context.table !== undefined && context.format !== undefined,
168
- handler: (context) => context.table !== undefined && context.format !== undefined
169
- ? insertTableRowColumn(context, context.table, context.format, false, true)
170
- : undefined,
240
+ active: (context) =>
241
+ context.table !== undefined && context.format !== undefined,
242
+ handler: (context) =>
243
+ context.table !== undefined && context.format !== undefined
244
+ ? insertTableRowColumn(
245
+ context,
246
+ context.table,
247
+ context.format,
248
+ false,
249
+ true
250
+ )
251
+ : undefined,
171
252
  },
172
253
  {
173
254
  icon: DeleteRowIcon,
@@ -179,12 +260,19 @@ const commands = [
179
260
  shift: false,
180
261
  key: 'Backspace',
181
262
  visible: (context) => context.table !== undefined,
182
- active: (context) => context.format !== undefined &&
263
+ active: (context) =>
264
+ context.format !== undefined &&
183
265
  context.table !== undefined &&
184
266
  context.table.getRowCount() > 1,
185
- handler: (context) => context.format !== undefined && context.table !== undefined
186
- ? deleteTableRowColumn(context, context.table, context.format, true)
187
- : undefined,
267
+ handler: (context) =>
268
+ context.format !== undefined && context.table !== undefined
269
+ ? deleteTableRowColumn(
270
+ context,
271
+ context.table,
272
+ context.format,
273
+ true
274
+ )
275
+ : undefined,
188
276
  },
189
277
  {
190
278
  icon: DeleteColumnIcon,
@@ -196,12 +284,19 @@ const commands = [
196
284
  shift: true,
197
285
  key: 'Backspace',
198
286
  visible: (context) => context.table !== undefined,
199
- active: (context) => context.format !== undefined &&
287
+ active: (context) =>
288
+ context.format !== undefined &&
200
289
  context.table !== undefined &&
201
290
  context.table.getColumnCount() > 1,
202
- handler: (context) => context.format !== undefined && context.table !== undefined
203
- ? deleteTableRowColumn(context, context.table, context.format, false)
204
- : undefined,
291
+ handler: (context) =>
292
+ context.format !== undefined && context.table !== undefined
293
+ ? deleteTableRowColumn(
294
+ context,
295
+ context.table,
296
+ context.format,
297
+ false
298
+ )
299
+ : undefined,
205
300
  },
206
301
  {
207
302
  icon: '➡️',
@@ -217,7 +312,10 @@ const commands = [
217
312
  handler: (context) => {
218
313
  if (context.format) {
219
314
  let caret = context.root
220
- .getNodeAfter(context.format, (node) => node instanceof FormatNode)
315
+ .getNodeAfter<FormatNode>(
316
+ context.format,
317
+ (node): node is FormatNode => node instanceof FormatNode
318
+ )
221
319
  ?.getFirstCaret();
222
320
  if (caret)
223
321
  return {
@@ -242,7 +340,10 @@ const commands = [
242
340
  handler: (context) => {
243
341
  if (context.format) {
244
342
  let caret = context.root
245
- .getNodeBefore(context.format, (node) => node instanceof FormatNode)
343
+ .getNodeBefore<FormatNode>(
344
+ context.format,
345
+ (node): node is FormatNode => node instanceof FormatNode
346
+ )
246
347
  ?.getFirstCaret();
247
348
  if (caret)
248
349
  return {
@@ -264,19 +365,25 @@ const commands = [
264
365
  visible: () => false,
265
366
  active: (context) => context.endIsTextOrAtom,
266
367
  handler: (context) => {
267
- if (context.end.node instanceof TextNode ||
368
+ if (
369
+ context.end.node instanceof TextNode ||
268
370
  context.end.node instanceof AtomNode ||
269
- context.end.node instanceof EmbedNode) {
270
- const nextCaret = context.root.getAdjacentCaret(context.end, false);
371
+ context.end.node instanceof EmbedNode
372
+ ) {
373
+ const nextCaret = context.root.getAdjacentCaret(
374
+ context.end,
375
+ false
376
+ );
271
377
  const sortedRange = context.root.sortRange(context.range);
272
378
  return {
273
379
  root: context.root,
274
- range: nextCaret === undefined
275
- ? {
276
- start: sortedRange.start,
277
- end: sortedRange.start,
278
- }
279
- : { start: nextCaret, end: nextCaret },
380
+ range:
381
+ nextCaret === undefined
382
+ ? {
383
+ start: sortedRange.start,
384
+ end: sortedRange.start,
385
+ }
386
+ : { start: nextCaret, end: nextCaret },
280
387
  };
281
388
  }
282
389
  },
@@ -293,10 +400,15 @@ const commands = [
293
400
  visible: false,
294
401
  active: (context) => context.endIsTextOrAtom,
295
402
  handler: (context) => {
296
- if (context.end.node instanceof TextNode ||
403
+ if (
404
+ context.end.node instanceof TextNode ||
297
405
  context.end.node instanceof AtomNode ||
298
- context.end.node instanceof EmbedNode) {
299
- const previous = context.end.node.previousWord(context.root, context.end.index);
406
+ context.end.node instanceof EmbedNode
407
+ ) {
408
+ const previous = context.end.node.previousWord(
409
+ context.root,
410
+ context.end.index
411
+ );
300
412
  return {
301
413
  root: context.root,
302
414
  range: { start: previous, end: previous },
@@ -340,12 +452,16 @@ const commands = [
340
452
  visible: false,
341
453
  active: (context) => context.endIsTextOrAtom,
342
454
  handler: (context) => {
343
- if (context.end.node instanceof TextNode ||
455
+ if (
456
+ context.end.node instanceof TextNode ||
344
457
  context.end.node instanceof AtomNode ||
345
- context.end.node instanceof EmbedNode) {
346
- const previous = context.root.getAdjacentCaret(context.end, false);
347
- if (previous === undefined)
348
- return;
458
+ context.end.node instanceof EmbedNode
459
+ ) {
460
+ const previous = context.root.getAdjacentCaret(
461
+ context.end,
462
+ false
463
+ );
464
+ if (previous === undefined) return;
349
465
  return {
350
466
  root: context.root,
351
467
  range: { start: context.start, end: previous },
@@ -365,10 +481,15 @@ const commands = [
365
481
  visible: false,
366
482
  active: (context) => context.endIsTextOrAtom,
367
483
  handler: (context) => {
368
- if (context.end.node instanceof TextNode ||
484
+ if (
485
+ context.end.node instanceof TextNode ||
369
486
  context.end.node instanceof AtomNode ||
370
- context.end.node instanceof EmbedNode) {
371
- const previous = context.end.node.previousWord(context.root, context.end.index);
487
+ context.end.node instanceof EmbedNode
488
+ ) {
489
+ const previous = context.end.node.previousWord(
490
+ context.root,
491
+ context.end.index
492
+ );
372
493
  return {
373
494
  root: context.root,
374
495
  range: { start: context.start, end: previous },
@@ -412,17 +533,23 @@ const commands = [
412
533
  visible: false,
413
534
  active: (context) => context.endIsTextOrAtom,
414
535
  handler: (context) => {
415
- if (context.end.node instanceof TextNode ||
536
+ if (
537
+ context.end.node instanceof TextNode ||
416
538
  context.end.node instanceof AtomNode ||
417
- context.end.node instanceof EmbedNode) {
418
- const nextCaret = context.root.getAdjacentCaret(context.end, true);
539
+ context.end.node instanceof EmbedNode
540
+ ) {
541
+ const nextCaret = context.root.getAdjacentCaret(
542
+ context.end,
543
+ true
544
+ );
419
545
  const sortedRange = context.root.sortRange(context.range);
420
546
  // If there is no next caret, move the caret to the largest of the current start and end.
421
547
  return {
422
548
  root: context.root,
423
- range: nextCaret === undefined
424
- ? { start: sortedRange.end, end: sortedRange.end }
425
- : { start: nextCaret, end: nextCaret },
549
+ range:
550
+ nextCaret === undefined
551
+ ? { start: sortedRange.end, end: sortedRange.end }
552
+ : { start: nextCaret, end: nextCaret },
426
553
  };
427
554
  }
428
555
  },
@@ -439,10 +566,15 @@ const commands = [
439
566
  visible: false,
440
567
  active: (context) => context.endIsTextOrAtom,
441
568
  handler: (context) => {
442
- if (context.end.node instanceof TextNode ||
569
+ if (
570
+ context.end.node instanceof TextNode ||
443
571
  context.end.node instanceof AtomNode ||
444
- context.end.node instanceof EmbedNode) {
445
- const next = context.end.node.nextWord(context.root, context.end.index);
572
+ context.end.node instanceof EmbedNode
573
+ ) {
574
+ const next = context.end.node.nextWord(
575
+ context.root,
576
+ context.end.index
577
+ );
446
578
  return {
447
579
  root: context.root,
448
580
  range: { start: next, end: next },
@@ -484,12 +616,13 @@ const commands = [
484
616
  visible: false,
485
617
  active: (context) => context.endIsTextOrAtom,
486
618
  handler: (context) => {
487
- if (context.end.node instanceof TextNode ||
619
+ if (
620
+ context.end.node instanceof TextNode ||
488
621
  context.end.node instanceof AtomNode ||
489
- context.end.node instanceof EmbedNode) {
622
+ context.end.node instanceof EmbedNode
623
+ ) {
490
624
  const next = context.root.getAdjacentCaret(context.end, true);
491
- if (next === undefined)
492
- return;
625
+ if (next === undefined) return;
493
626
  return {
494
627
  root: context.root,
495
628
  range: { start: context.start, end: next },
@@ -509,10 +642,15 @@ const commands = [
509
642
  visible: false,
510
643
  active: (context) => context.endIsTextOrAtom,
511
644
  handler: (context) => {
512
- if (context.end.node instanceof TextNode ||
645
+ if (
646
+ context.end.node instanceof TextNode ||
513
647
  context.end.node instanceof AtomNode ||
514
- context.end.node instanceof EmbedNode) {
515
- const previous = context.end.node.nextWord(context.root, context.end.index);
648
+ context.end.node instanceof EmbedNode
649
+ ) {
650
+ const previous = context.end.node.nextWord(
651
+ context.root,
652
+ context.end.index
653
+ );
516
654
  return {
517
655
  root: context.root,
518
656
  range: { start: context.start, end: previous },
@@ -568,8 +706,10 @@ const commands = [
568
706
  };
569
707
  }
570
708
  // If in a code node, expand to the code.
571
- else if (context.block instanceof CodeNode &&
572
- context.range.start.node === context.block.getCodeNode()) {
709
+ else if (
710
+ context.block instanceof CodeNode &&
711
+ context.range.start.node === context.block.getCodeNode()
712
+ ) {
573
713
  const code = context.block.getCodeNode();
574
714
  return {
575
715
  root: context.root,
@@ -580,9 +720,11 @@ const commands = [
580
720
  };
581
721
  }
582
722
  // If in a non paragraph block, expand to the format of whatever format we're in.
583
- else if (context.paragraph === undefined &&
723
+ else if (
724
+ context.paragraph === undefined &&
584
725
  context.block &&
585
- context.format) {
726
+ context.format
727
+ ) {
586
728
  return {
587
729
  root: context.root,
588
730
  range: {
@@ -590,8 +732,7 @@ const commands = [
590
732
  end: context.format.getLastCaret(),
591
733
  },
592
734
  };
593
- }
594
- else {
735
+ } else {
595
736
  // Find the first and last caret of the entire chapter.
596
737
  const text = context.root?.getTextNodes();
597
738
  if (text && text.length > 0) {
@@ -691,19 +832,31 @@ const commands = [
691
832
  visible: false,
692
833
  active: true,
693
834
  handler: (context) => {
694
- if (context.root === undefined)
695
- return;
835
+ if (context.root === undefined) return;
696
836
  if (context.isSelection) {
697
- const edit = context.root.withRangeFormatted(context.range, undefined);
698
- if (edit === undefined)
699
- return;
700
- return rootWithNode(context, context.root, edit.root, () => edit.range.start);
701
- }
702
- else {
703
- const edit = context.root.withoutAdjacentContent(context.start, false);
704
- if (edit === undefined)
705
- return;
706
- return rootWithNode(context, context.root, edit.root, () => edit.range.start);
837
+ const edit = context.root.withRangeFormatted(
838
+ context.range,
839
+ undefined
840
+ );
841
+ if (edit === undefined) return;
842
+ return rootWithNode<RootNode>(
843
+ context,
844
+ context.root,
845
+ edit.root as RootNode,
846
+ () => edit.range.start
847
+ );
848
+ } else {
849
+ const edit = context.root.withoutAdjacentContent(
850
+ context.start,
851
+ false
852
+ );
853
+ if (edit === undefined) return;
854
+ return rootWithNode<RootNode>(
855
+ context,
856
+ context.root,
857
+ edit.root as RootNode,
858
+ () => edit.range.start
859
+ );
707
860
  }
708
861
  },
709
862
  },
@@ -719,19 +872,31 @@ const commands = [
719
872
  visible: false,
720
873
  active: true,
721
874
  handler: (context) => {
722
- if (context.root === undefined)
723
- return;
875
+ if (context.root === undefined) return;
724
876
  if (context.isSelection) {
725
- const edit = context.root.withRangeFormatted(context.range, undefined);
726
- if (edit === undefined)
727
- return;
728
- return rootWithNode(context, context.root, edit.root, () => edit.range.start);
729
- }
730
- else {
731
- const edit = context.root.withoutAdjacentContent(context.start, true);
732
- if (edit === undefined)
733
- return;
734
- return rootWithNode(context, context.root, edit.root, () => edit.range.start);
877
+ const edit = context.root.withRangeFormatted(
878
+ context.range,
879
+ undefined
880
+ );
881
+ if (edit === undefined) return;
882
+ return rootWithNode<RootNode>(
883
+ context,
884
+ context.root,
885
+ edit.root as RootNode,
886
+ () => edit.range.start
887
+ );
888
+ } else {
889
+ const edit = context.root.withoutAdjacentContent(
890
+ context.start,
891
+ true
892
+ );
893
+ if (edit === undefined) return;
894
+ return rootWithNode<RootNode>(
895
+ context,
896
+ context.root,
897
+ edit.root as RootNode,
898
+ () => edit.range.start
899
+ );
735
900
  }
736
901
  },
737
902
  },
@@ -747,14 +912,20 @@ const commands = [
747
912
  visible: false,
748
913
  active: (context) => context.code !== undefined,
749
914
  handler: (context) => {
750
- if (context.code?.getCodeNode() !== context.start.node)
751
- return;
752
- const newText = context.start.node.withCharacterAt('\n', context.start.index);
753
- if (newText === undefined)
754
- return;
755
- return rootWithNode(context, context.start.node, newText, (text) => {
756
- return { node: text, index: context.start.index + 1 };
757
- });
915
+ if (context.code?.getCodeNode() !== context.start.node) return;
916
+ const newText = context.start.node.withCharacterAt(
917
+ '\n',
918
+ context.start.index
919
+ );
920
+ if (newText === undefined) return;
921
+ return rootWithNode(
922
+ context,
923
+ context.start.node,
924
+ newText,
925
+ (text) => {
926
+ return { node: text, index: context.start.index + 1 };
927
+ }
928
+ );
758
929
  },
759
930
  },
760
931
  {
@@ -769,52 +940,69 @@ const commands = [
769
940
  visible: false,
770
941
  active: (context) => context.list !== undefined,
771
942
  handler: (context) => {
772
- if (context.list === undefined)
773
- return;
943
+ if (context.list === undefined) return;
774
944
  const lastItem = context.list.getLastItem();
775
945
  const lastCaret = lastItem?.getLastCaret();
776
946
  // If we're at the last item in the list and it's empty, then add a
777
- if (lastItem !== undefined &&
947
+ if (
948
+ lastItem !== undefined &&
778
949
  lastCaret !== undefined &&
779
950
  lastCaret.node instanceof TextNode &&
780
951
  lastCaret.node.getLength() === 0 &&
781
952
  lastCaret.node === context.end.node &&
782
- lastCaret.index === context.end.index) {
953
+ lastCaret.index === context.end.index
954
+ ) {
783
955
  const listParent = context.list.getParent(context.root);
784
956
  if (listParent instanceof ListNode) {
785
957
  const newSublist = context.list.withoutItem(lastItem);
786
- if (newSublist === undefined)
787
- return;
788
- const newListWithoutSublistItem = listParent.withChildReplaced(context.list, newSublist);
789
- if (newListWithoutSublistItem === undefined)
790
- return;
791
- const newListWithSublistItem = newListWithoutSublistItem.withItemAfter(lastItem, newSublist);
792
- if (newListWithSublistItem === undefined)
793
- return;
794
- return rootWithNode(context, listParent, newListWithSublistItem, () => lastCaret);
795
- }
796
- else if (listParent instanceof BlocksNode) {
958
+ if (newSublist === undefined) return;
959
+ const newListWithoutSublistItem =
960
+ listParent.withChildReplaced(context.list, newSublist);
961
+ if (newListWithoutSublistItem === undefined) return;
962
+ const newListWithSublistItem =
963
+ newListWithoutSublistItem.withItemAfter(
964
+ lastItem,
965
+ newSublist
966
+ );
967
+ if (newListWithSublistItem === undefined) return;
968
+ return rootWithNode(
969
+ context,
970
+ listParent,
971
+ newListWithSublistItem,
972
+ () => lastCaret
973
+ );
974
+ } else if (listParent instanceof BlocksNode) {
797
975
  const listWithoutItem = context.list.withoutItem(lastItem);
798
- if (listWithoutItem === undefined)
799
- return;
976
+ if (listWithoutItem === undefined) return;
800
977
  const newBlocks = listParent
801
978
  .withChildReplaced(context.list, listWithoutItem)
802
- ?.withBlockInsertedAfter(listWithoutItem, new ParagraphNode(0, lastItem));
803
- if (newBlocks === undefined)
804
- return;
805
- return rootWithNode(context, listParent, newBlocks, () => lastCaret);
979
+ ?.withBlockInsertedAfter(
980
+ listWithoutItem,
981
+ new ParagraphNode(0, lastItem)
982
+ );
983
+ if (newBlocks === undefined) return;
984
+ return rootWithNode(
985
+ context,
986
+ listParent,
987
+ newBlocks,
988
+ () => lastCaret
989
+ );
806
990
  }
807
- }
808
- else
809
- return rootWithNode(context, context.list, context.list?.withItemSplit(context.range.start), (newList) => {
810
- const index = context.list?.getItemContaining(context.range.start);
811
- if (index === undefined)
812
- return;
813
- const item = newList.getItem(index + 1);
814
- if (item === undefined)
815
- return;
816
- return item.getFirstCaret();
817
- });
991
+ } else
992
+ return rootWithNode(
993
+ context,
994
+ context.list,
995
+ context.list?.withItemSplit(context.range.start),
996
+ (newList) => {
997
+ const index = context.list?.getItemContaining(
998
+ context.range.start
999
+ );
1000
+ if (index === undefined) return;
1001
+ const item = (newList as ListNode).getItem(index + 1);
1002
+ if (item === undefined) return;
1003
+ return item.getFirstCaret();
1004
+ }
1005
+ );
818
1006
  },
819
1007
  },
820
1008
  {
@@ -827,12 +1015,17 @@ const commands = [
827
1015
  shift: false,
828
1016
  key: 'Enter',
829
1017
  visible: false,
830
- active: (context) => context.atom === undefined && context.blocks !== undefined,
1018
+ active: (context) =>
1019
+ context.atom === undefined && context.blocks !== undefined,
831
1020
  handler: (context) => {
832
1021
  const edit = context.blocks?.withSelectionSplit(context.range);
833
- if (edit === undefined)
834
- return;
835
- return rootWithNode(context, context.blocks, edit.root, () => edit.range.start);
1022
+ if (edit === undefined) return;
1023
+ return rootWithNode(
1024
+ context,
1025
+ context.blocks,
1026
+ edit.root,
1027
+ () => edit.range.start
1028
+ );
836
1029
  },
837
1030
  },
838
1031
  {
@@ -846,7 +1039,12 @@ const commands = [
846
1039
  key: 'Tab',
847
1040
  visible: (context) => context.list !== undefined,
848
1041
  active: (context) => context.list !== undefined,
849
- handler: (context) => rootWithNode(context, context.blocks, context.blocks?.withListsIndented(context.range, true)),
1042
+ handler: (context) =>
1043
+ rootWithNode(
1044
+ context,
1045
+ context.blocks,
1046
+ context.blocks?.withListsIndented(context.range, true)
1047
+ ),
850
1048
  },
851
1049
  {
852
1050
  icon: UnindentIcon,
@@ -858,9 +1056,15 @@ const commands = [
858
1056
  shift: true,
859
1057
  key: 'Tab',
860
1058
  visible: (context) => context.list !== undefined,
861
- active: (context) => context.list !== undefined &&
1059
+ active: (context) =>
1060
+ context.list !== undefined &&
862
1061
  context.list.isInside(context.root, ListNode),
863
- handler: (context) => rootWithNode(context, context.blocks, context.blocks?.withListsIndented(context.range, false)),
1062
+ handler: (context) =>
1063
+ rootWithNode(
1064
+ context,
1065
+ context.blocks,
1066
+ context.blocks?.withListsIndented(context.range, false)
1067
+ ),
864
1068
  },
865
1069
  {
866
1070
  icon: ClearIcon,
@@ -873,7 +1077,8 @@ const commands = [
873
1077
  key: '0',
874
1078
  visible: true,
875
1079
  active: (context) => context.startIsText || context.endIsText,
876
- handler: (context) => context.root.withRangeFormatted(context.range, ''),
1080
+ handler: (context) =>
1081
+ context.root.withRangeFormatted(context.range, ''),
877
1082
  },
878
1083
  {
879
1084
  icon: BoldIcon,
@@ -886,7 +1091,8 @@ const commands = [
886
1091
  key: 'b',
887
1092
  visible: true,
888
1093
  active: (context) => context.startIsText || context.endIsText,
889
- handler: (context) => context.root.withRangeFormatted(context.range, '*'),
1094
+ handler: (context) =>
1095
+ context.root.withRangeFormatted(context.range, '*'),
890
1096
  },
891
1097
  {
892
1098
  description: 'italic',
@@ -899,7 +1105,8 @@ const commands = [
899
1105
  key: 'i',
900
1106
  visible: true,
901
1107
  active: (context) => context.startIsText || context.endIsText,
902
- handler: (context) => context.root.withRangeFormatted(context.range, '_'),
1108
+ handler: (context) =>
1109
+ context.root.withRangeFormatted(context.range, '_'),
903
1110
  },
904
1111
  {
905
1112
  icon: SubscriptIcon,
@@ -912,7 +1119,8 @@ const commands = [
912
1119
  key: ',',
913
1120
  visible: true,
914
1121
  active: (context) => context.startIsText || context.endIsText,
915
- handler: (context) => context.root.withRangeFormatted(context.range, 'v'),
1122
+ handler: (context) =>
1123
+ context.root.withRangeFormatted(context.range, 'v'),
916
1124
  },
917
1125
  {
918
1126
  icon: SuperscriptIcon,
@@ -925,7 +1133,8 @@ const commands = [
925
1133
  key: '.',
926
1134
  visible: true,
927
1135
  active: (context) => context.startIsText || context.endIsText,
928
- handler: (context) => context.root.withRangeFormatted(context.range, '^'),
1136
+ handler: (context) =>
1137
+ context.root.withRangeFormatted(context.range, '^'),
929
1138
  },
930
1139
  {
931
1140
  icon: CodeIcon,
@@ -938,9 +1147,20 @@ const commands = [
938
1147
  key: 'e',
939
1148
  visible: true,
940
1149
  active: (context) => context.startIsText || context.endIsText,
941
- handler: (context) => context.meta instanceof InlineCodeNode
942
- ? rootWithNode(context, context.format, context.format?.withSegmentReplaced(context.meta, context.meta.getText()))
943
- : context.root.withSegmentAtSelection(context.range, (text) => new InlineCodeNode(new TextNode(text))),
1150
+ handler: (context) =>
1151
+ context.meta instanceof InlineCodeNode
1152
+ ? rootWithNode(
1153
+ context,
1154
+ context.format,
1155
+ context.format?.withSegmentReplaced(
1156
+ context.meta,
1157
+ context.meta.getText()
1158
+ )
1159
+ )
1160
+ : context.root.withSegmentAtSelection(
1161
+ context.range,
1162
+ (text) => new InlineCodeNode(new TextNode(text))
1163
+ ),
944
1164
  },
945
1165
  {
946
1166
  icon: LinkIcon,
@@ -952,11 +1172,23 @@ const commands = [
952
1172
  shift: false,
953
1173
  key: 'k',
954
1174
  visible: true,
955
- active: (context) => (context.atom === undefined && context.meta === undefined) ||
1175
+ active: (context) =>
1176
+ (context.atom === undefined && context.meta === undefined) ||
956
1177
  context.meta instanceof LinkNode,
957
- handler: (context) => context.meta instanceof LinkNode
958
- ? rootWithNode(context, context.format, context.format?.withSegmentReplaced(context.meta, context.meta.getText()))
959
- : context.root.withSegmentAtSelection(context.range, (text) => new LinkNode(new TextNode(text))),
1178
+ handler: (context) =>
1179
+ context.meta instanceof LinkNode
1180
+ ? rootWithNode(
1181
+ context,
1182
+ context.format,
1183
+ context.format?.withSegmentReplaced(
1184
+ context.meta,
1185
+ context.meta.getText()
1186
+ )
1187
+ )
1188
+ : context.root.withSegmentAtSelection(
1189
+ context.range,
1190
+ (text) => new LinkNode(new TextNode(text))
1191
+ ),
960
1192
  },
961
1193
  {
962
1194
  icon: DefineIcon,
@@ -967,15 +1199,28 @@ const commands = [
967
1199
  alt: false,
968
1200
  shift: false,
969
1201
  key: 'd',
970
- visible: (context) => context.chapter &&
1202
+ visible: (context) =>
1203
+ context.chapter &&
971
1204
  context.atom === undefined &&
972
1205
  context.meta === undefined,
973
- active: (context) => context.chapter &&
1206
+ active: (context) =>
1207
+ context.chapter &&
974
1208
  context.atom === undefined &&
975
1209
  context.meta === undefined,
976
- handler: (context) => context.meta instanceof DefinitionNode
977
- ? rootWithNode(context, context.format, context.format?.withSegmentReplaced(context.meta, context.meta.getText()))
978
- : context.root.withSegmentAtSelection(context.range, (text) => new DefinitionNode(new TextNode(text))),
1210
+ handler: (context) =>
1211
+ context.meta instanceof DefinitionNode
1212
+ ? rootWithNode(
1213
+ context,
1214
+ context.format,
1215
+ context.format?.withSegmentReplaced(
1216
+ context.meta,
1217
+ context.meta.getText()
1218
+ )
1219
+ )
1220
+ : context.root.withSegmentAtSelection(
1221
+ context.range,
1222
+ (text) => new DefinitionNode(new TextNode(text))
1223
+ ),
979
1224
  },
980
1225
  {
981
1226
  icon: FootnoteIcon,
@@ -986,13 +1231,20 @@ const commands = [
986
1231
  alt: false,
987
1232
  shift: false,
988
1233
  key: 'f',
989
- visible: (context) => context.chapter &&
1234
+ visible: (context) =>
1235
+ context.chapter &&
990
1236
  context.atom === undefined &&
991
1237
  context.meta === undefined,
992
- active: (context) => context.chapter &&
1238
+ active: (context) =>
1239
+ context.chapter &&
993
1240
  context.atom === undefined &&
994
1241
  context.meta === undefined,
995
- handler: (context) => context.root.withSegmentAtSelection(context.range, (text) => new FootnoteNode(new FormatNode('', [new TextNode(text)]))),
1242
+ handler: (context) =>
1243
+ context.root.withSegmentAtSelection(
1244
+ context.range,
1245
+ (text) =>
1246
+ new FootnoteNode(new FormatNode('', [new TextNode(text)]))
1247
+ ),
996
1248
  },
997
1249
  {
998
1250
  icon: CitationIcon,
@@ -1003,13 +1255,19 @@ const commands = [
1003
1255
  alt: false,
1004
1256
  shift: false,
1005
1257
  key: 'o',
1006
- visible: (context) => context.chapter &&
1258
+ visible: (context) =>
1259
+ context.chapter &&
1007
1260
  context.atom === undefined &&
1008
1261
  context.meta === undefined,
1009
- active: (context) => context.chapter &&
1262
+ active: (context) =>
1263
+ context.chapter &&
1010
1264
  context.atom === undefined &&
1011
1265
  context.meta === undefined,
1012
- handler: (context) => context.root.withSegmentAtSelection(context.range, () => new CitationsNode([])),
1266
+ handler: (context) =>
1267
+ context.root.withSegmentAtSelection(
1268
+ context.range,
1269
+ () => new CitationsNode([])
1270
+ ),
1013
1271
  },
1014
1272
  {
1015
1273
  icon: LabelIcon,
@@ -1020,13 +1278,19 @@ const commands = [
1020
1278
  alt: false,
1021
1279
  shift: false,
1022
1280
  key: 'l',
1023
- visible: (context) => context.chapter &&
1281
+ visible: (context) =>
1282
+ context.chapter &&
1024
1283
  context.atom === undefined &&
1025
1284
  context.meta === undefined,
1026
- active: (context) => context.chapter &&
1285
+ active: (context) =>
1286
+ context.chapter &&
1027
1287
  context.atom === undefined &&
1028
1288
  context.meta === undefined,
1029
- handler: (context) => context.root.withSegmentAtSelection(context.range, () => new LabelNode('')),
1289
+ handler: (context) =>
1290
+ context.root.withSegmentAtSelection(
1291
+ context.range,
1292
+ () => new LabelNode('')
1293
+ ),
1030
1294
  },
1031
1295
  {
1032
1296
  icon: CommentIcon,
@@ -1037,13 +1301,20 @@ const commands = [
1037
1301
  alt: false,
1038
1302
  shift: false,
1039
1303
  key: "'",
1040
- visible: (context) => context.chapter &&
1304
+ visible: (context) =>
1305
+ context.chapter &&
1041
1306
  context.atom === undefined &&
1042
1307
  context.meta === undefined,
1043
- active: (context) => context.chapter &&
1308
+ active: (context) =>
1309
+ context.chapter &&
1044
1310
  context.atom === undefined &&
1045
1311
  context.meta === undefined,
1046
- handler: (context) => context.root.withSegmentAtSelection(context.range, (text) => new CommentNode(new FormatNode('', [new TextNode(text)]))),
1312
+ handler: (context) =>
1313
+ context.root.withSegmentAtSelection(
1314
+ context.range,
1315
+ (text) =>
1316
+ new CommentNode(new FormatNode('', [new TextNode(text)]))
1317
+ ),
1047
1318
  },
1048
1319
  {
1049
1320
  icon: ParagraphIcon,
@@ -1054,14 +1325,19 @@ const commands = [
1054
1325
  alt: true,
1055
1326
  shift: false,
1056
1327
  code: 'Digit0',
1057
- visible: (context) => context.paragraph !== undefined &&
1328
+ visible: (context) =>
1329
+ context.paragraph !== undefined &&
1058
1330
  context.paragraph.getLevel() !== 0,
1059
- active: (context) => context.paragraph !== undefined &&
1331
+ active: (context) =>
1332
+ context.paragraph !== undefined &&
1060
1333
  context.paragraph.getLevel() !== 0,
1061
1334
  handler: (context) => {
1062
- if (context.paragraph === undefined)
1063
- return;
1064
- return rootWithNode(context, context.paragraph, context.paragraph.withLevel(0));
1335
+ if (context.paragraph === undefined) return;
1336
+ return rootWithNode(
1337
+ context,
1338
+ context.paragraph,
1339
+ context.paragraph.withLevel(0)
1340
+ );
1065
1341
  },
1066
1342
  },
1067
1343
  {
@@ -1074,9 +1350,15 @@ const commands = [
1074
1350
  shift: false,
1075
1351
  code: 'Digit1',
1076
1352
  visible: (context) => context.paragraph !== undefined,
1077
- active: (context) => context.paragraph !== undefined &&
1353
+ active: (context) =>
1354
+ context.paragraph !== undefined &&
1078
1355
  context.paragraph.getLevel() !== 1,
1079
- handler: (context) => rootWithNode(context, context.paragraph, context.paragraph?.withLevel(1)),
1356
+ handler: (context) =>
1357
+ rootWithNode(
1358
+ context,
1359
+ context.paragraph,
1360
+ context.paragraph?.withLevel(1)
1361
+ ),
1080
1362
  },
1081
1363
  {
1082
1364
  icon: Header2Icon,
@@ -1088,9 +1370,15 @@ const commands = [
1088
1370
  shift: false,
1089
1371
  code: 'Digit2',
1090
1372
  visible: (context) => context.paragraph !== undefined,
1091
- active: (context) => context.paragraph !== undefined &&
1373
+ active: (context) =>
1374
+ context.paragraph !== undefined &&
1092
1375
  context.paragraph.getLevel() !== 2,
1093
- handler: (context) => rootWithNode(context, context.paragraph, context.paragraph?.withLevel(2)),
1376
+ handler: (context) =>
1377
+ rootWithNode(
1378
+ context,
1379
+ context.paragraph,
1380
+ context.paragraph?.withLevel(2)
1381
+ ),
1094
1382
  },
1095
1383
  {
1096
1384
  icon: Header3Icon,
@@ -1102,9 +1390,15 @@ const commands = [
1102
1390
  shift: false,
1103
1391
  code: 'Digit3',
1104
1392
  visible: (context) => context.paragraph !== undefined,
1105
- active: (context) => context.paragraph !== undefined &&
1393
+ active: (context) =>
1394
+ context.paragraph !== undefined &&
1106
1395
  context.paragraph.getLevel() !== 3,
1107
- handler: (context) => rootWithNode(context, context.paragraph, context.paragraph?.withLevel(3)),
1396
+ handler: (context) =>
1397
+ rootWithNode(
1398
+ context,
1399
+ context.paragraph,
1400
+ context.paragraph?.withLevel(3)
1401
+ ),
1108
1402
  },
1109
1403
  {
1110
1404
  icon: RuleIcon,
@@ -1116,10 +1410,19 @@ const commands = [
1116
1410
  shift: false,
1117
1411
  key: 'u',
1118
1412
  visible: (context) => context.paragraph !== undefined,
1119
- active: (context) => context.paragraph !== undefined && context.atParagraphStart,
1120
- handler: (context) => context.paragraph
1121
- ? rootWithNode(context, context.blocks, context.blocks?.withBlockInsertedBefore(context.paragraph, new RuleNode()))
1122
- : undefined,
1413
+ active: (context) =>
1414
+ context.paragraph !== undefined && context.atParagraphStart,
1415
+ handler: (context) =>
1416
+ context.paragraph
1417
+ ? rootWithNode(
1418
+ context,
1419
+ context.blocks,
1420
+ context.blocks?.withBlockInsertedBefore(
1421
+ context.paragraph,
1422
+ new RuleNode()
1423
+ )
1424
+ )
1425
+ : undefined,
1123
1426
  },
1124
1427
  {
1125
1428
  icon: CalloutIcon,
@@ -1131,13 +1434,22 @@ const commands = [
1131
1434
  shift: true,
1132
1435
  key: '-',
1133
1436
  visible: (context) => context.paragraph !== undefined,
1134
- active: (context) => context.paragraph !== undefined && context.atParagraphStart,
1437
+ active: (context) =>
1438
+ context.paragraph !== undefined && context.atParagraphStart,
1135
1439
  handler: (context) => {
1136
1440
  // If the caret is in a paragraph in a blocks node, insert a callout before the current paragraph.
1137
1441
  if (context.blocks && context.paragraph) {
1138
1442
  // Make a new callout node with an empty paragraph, insert it before the paragraph the caret is in, and place the caret inside the empty paragraph.
1139
1443
  const newParagraph = new ParagraphNode();
1140
- return rootWithNode(context, context.blocks, context.blocks.withBlockInsertedBefore(context.paragraph, new CalloutNode([newParagraph])), () => newParagraph.getFirstCaret());
1444
+ return rootWithNode(
1445
+ context,
1446
+ context.blocks,
1447
+ context.blocks.withBlockInsertedBefore(
1448
+ context.paragraph,
1449
+ new CalloutNode([newParagraph])
1450
+ ),
1451
+ () => newParagraph.getFirstCaret()
1452
+ );
1141
1453
  }
1142
1454
  },
1143
1455
  },
@@ -1151,12 +1463,21 @@ const commands = [
1151
1463
  shift: true,
1152
1464
  key: "'",
1153
1465
  visible: (context) => context.paragraph !== undefined,
1154
- active: (context) => context.paragraph !== undefined && context.atParagraphStart,
1466
+ active: (context) =>
1467
+ context.paragraph !== undefined && context.atParagraphStart,
1155
1468
  handler: (context) => {
1156
1469
  if (context.blocks && context.paragraph) {
1157
1470
  // Make a new quote and place the caret inside the quote's first empty paragraph.
1158
1471
  const newParagraph = new ParagraphNode();
1159
- return rootWithNode(context, context.blocks, context.blocks.withBlockInsertedBefore(context.paragraph, new QuoteNode([newParagraph])), () => newParagraph.getFirstCaret());
1472
+ return rootWithNode(
1473
+ context,
1474
+ context.blocks,
1475
+ context.blocks.withBlockInsertedBefore(
1476
+ context.paragraph,
1477
+ new QuoteNode([newParagraph])
1478
+ ),
1479
+ () => newParagraph.getFirstCaret()
1480
+ );
1160
1481
  }
1161
1482
  },
1162
1483
  },
@@ -1170,13 +1491,22 @@ const commands = [
1170
1491
  shift: true,
1171
1492
  key: 's',
1172
1493
  visible: (context) => context.paragraph !== undefined,
1173
- active: (context) => context.paragraph !== undefined && context.atParagraphStart,
1494
+ active: (context) =>
1495
+ context.paragraph !== undefined && context.atParagraphStart,
1174
1496
  handler: (context) => {
1175
1497
  if (context.blocks && context.paragraph) {
1176
1498
  const newCode = new CodeNode(new TextNode(), 'plaintext', '|');
1177
- return rootWithNode(context, context.blocks, context.blocks.withBlockInsertedBefore(context.paragraph, newCode), () => {
1178
- return { node: newCode.getCodeNode(), index: 0 };
1179
- });
1499
+ return rootWithNode(
1500
+ context,
1501
+ context.blocks,
1502
+ context.blocks.withBlockInsertedBefore(
1503
+ context.paragraph,
1504
+ newCode
1505
+ ),
1506
+ () => {
1507
+ return { node: newCode.getCodeNode(), index: 0 };
1508
+ }
1509
+ );
1180
1510
  }
1181
1511
  },
1182
1512
  },
@@ -1190,12 +1520,21 @@ const commands = [
1190
1520
  shift: true,
1191
1521
  key: 'i',
1192
1522
  visible: (context) => context.paragraph !== undefined,
1193
- active: (context) => context.paragraph !== undefined && context.atParagraphStart,
1523
+ active: (context) =>
1524
+ context.paragraph !== undefined && context.atParagraphStart,
1194
1525
  handler: (context) => {
1195
1526
  if (context.blocks && context.paragraph) {
1196
1527
  // Place the caret inside the code's code node.
1197
1528
  const newEmbed = new EmbedNode('', '');
1198
- return rootWithNode(context, context.blocks, context.blocks.withBlockInsertedBefore(context.paragraph, newEmbed), () => newEmbed.getCaption().getFirstCaret());
1529
+ return rootWithNode(
1530
+ context,
1531
+ context.blocks,
1532
+ context.blocks.withBlockInsertedBefore(
1533
+ context.paragraph,
1534
+ newEmbed
1535
+ ),
1536
+ () => newEmbed.getCaption().getFirstCaret()
1537
+ );
1199
1538
  }
1200
1539
  },
1201
1540
  },
@@ -1209,23 +1548,36 @@ const commands = [
1209
1548
  shift: false,
1210
1549
  key: '[',
1211
1550
  visible: (context) => context.paragraph !== undefined,
1212
- active: (context) => context.paragraph !== undefined && context.atParagraphStart,
1551
+ active: (context) =>
1552
+ context.paragraph !== undefined && context.atParagraphStart,
1213
1553
  handler: (context) => {
1214
1554
  if (context.blocks && context.paragraph) {
1215
1555
  // Create a 3x3 of table rows and columns
1216
1556
  // Return a caret corresponding to the first cell.
1217
- const newRows = [[], [], []];
1557
+ const newRows: FormatNode[][] = [[], [], []];
1218
1558
  for (let r = 0; r < Math.max(1, 3); r++) {
1219
1559
  for (let c = 0; c < Math.max(1, 3); c++)
1220
1560
  newRows[r].push(new FormatNode('', [new TextNode()]));
1221
1561
  }
1222
- const newTable = new TableNode(newRows, '|', new FormatNode('', [new TextNode()]));
1223
- return rootWithNode(context, context.blocks, context.blocks.withBlockInsertedBefore(context.paragraph, newTable), () => {
1224
- return {
1225
- node: newTable.getRows()[0][0].getTextNodes()[0],
1226
- index: 0,
1227
- };
1228
- });
1562
+ const newTable = new TableNode(
1563
+ newRows,
1564
+ '|',
1565
+ new FormatNode('', [new TextNode()])
1566
+ );
1567
+ return rootWithNode(
1568
+ context,
1569
+ context.blocks,
1570
+ context.blocks.withBlockInsertedBefore(
1571
+ context.paragraph,
1572
+ newTable
1573
+ ),
1574
+ () => {
1575
+ return {
1576
+ node: newTable.getRows()[0][0].getTextNodes()[0],
1577
+ index: 0,
1578
+ };
1579
+ }
1580
+ );
1229
1581
  }
1230
1582
  },
1231
1583
  },
@@ -1238,9 +1590,16 @@ const commands = [
1238
1590
  alt: false,
1239
1591
  shift: true,
1240
1592
  key: '7',
1241
- visible: (context) => context.paragraph !== undefined && context.list === undefined,
1242
- active: (context) => context.paragraph !== undefined && context.list === undefined,
1243
- handler: (context) => rootWithNode(context, context.blocks, context.blocks?.withParagraphsAsLists(context.range, false)),
1593
+ visible: (context) =>
1594
+ context.paragraph !== undefined && context.list === undefined,
1595
+ active: (context) =>
1596
+ context.paragraph !== undefined && context.list === undefined,
1597
+ handler: (context) =>
1598
+ rootWithNode(
1599
+ context,
1600
+ context.blocks,
1601
+ context.blocks?.withParagraphsAsLists(context.range, false)
1602
+ ),
1244
1603
  },
1245
1604
  {
1246
1605
  icon: NumbersIcon,
@@ -1251,9 +1610,16 @@ const commands = [
1251
1610
  alt: false,
1252
1611
  shift: true,
1253
1612
  key: '8',
1254
- visible: (context) => context.paragraph !== undefined && context.list === undefined,
1255
- active: (context) => context.paragraph !== undefined && context.list === undefined,
1256
- handler: (context) => rootWithNode(context, context.blocks, context.blocks?.withParagraphsAsLists(context.range, true)),
1613
+ visible: (context) =>
1614
+ context.paragraph !== undefined && context.list === undefined,
1615
+ active: (context) =>
1616
+ context.paragraph !== undefined && context.list === undefined,
1617
+ handler: (context) =>
1618
+ rootWithNode(
1619
+ context,
1620
+ context.blocks,
1621
+ context.blocks?.withParagraphsAsLists(context.range, true)
1622
+ ),
1257
1623
  },
1258
1624
  {
1259
1625
  icon: BulletsIcon,
@@ -1264,11 +1630,18 @@ const commands = [
1264
1630
  alt: false,
1265
1631
  shift: true,
1266
1632
  key: '7',
1267
- visible: (context) => context.list !== undefined && context.list.isNumbered(),
1268
- active: (context) => context.list !== undefined && context.list.isNumbered(),
1269
- handler: (context) => context.list
1270
- ? rootWithNode(context, context.blocks, context.blocks?.withListAsStyle(context.list, false))
1271
- : undefined,
1633
+ visible: (context) =>
1634
+ context.list !== undefined && context.list.isNumbered(),
1635
+ active: (context) =>
1636
+ context.list !== undefined && context.list.isNumbered(),
1637
+ handler: (context) =>
1638
+ context.list
1639
+ ? rootWithNode(
1640
+ context,
1641
+ context.blocks,
1642
+ context.blocks?.withListAsStyle(context.list, false)
1643
+ )
1644
+ : undefined,
1272
1645
  },
1273
1646
  {
1274
1647
  icon: NumbersIcon,
@@ -1279,11 +1652,18 @@ const commands = [
1279
1652
  alt: false,
1280
1653
  shift: true,
1281
1654
  key: '8',
1282
- visible: (context) => context.list !== undefined && !context.list.isNumbered(),
1283
- active: (context) => context.list !== undefined && !context.list.isNumbered(),
1284
- handler: (context) => context.list
1285
- ? rootWithNode(context, context.blocks, context.blocks?.withListAsStyle(context.list, true))
1286
- : undefined,
1655
+ visible: (context) =>
1656
+ context.list !== undefined && !context.list.isNumbered(),
1657
+ active: (context) =>
1658
+ context.list !== undefined && !context.list.isNumbered(),
1659
+ handler: (context) =>
1660
+ context.list
1661
+ ? rootWithNode(
1662
+ context,
1663
+ context.blocks,
1664
+ context.blocks?.withListAsStyle(context.list, true)
1665
+ )
1666
+ : undefined,
1287
1667
  },
1288
1668
  {
1289
1669
  icon: ParagraphIcon,
@@ -1296,7 +1676,12 @@ const commands = [
1296
1676
  key: ['7', '8'],
1297
1677
  visible: (context) => context.list !== undefined,
1298
1678
  active: (context) => context.list !== undefined,
1299
- handler: (context) => rootWithNode(context, context.blocks, context.blocks?.withListsAsParagraphs(context.range)),
1679
+ handler: (context) =>
1680
+ rootWithNode(
1681
+ context,
1682
+ context.blocks,
1683
+ context.blocks?.withListsAsParagraphs(context.range)
1684
+ ),
1300
1685
  },
1301
1686
  {
1302
1687
  icon: UndoIcon,
@@ -1308,7 +1693,8 @@ const commands = [
1308
1693
  shift: false,
1309
1694
  key: 'z',
1310
1695
  visible: true,
1311
- active: (context) => context.undoStack.length > 0 &&
1696
+ active: (context) =>
1697
+ context.undoStack.length > 0 &&
1312
1698
  context.undoPosition < context.undoStack.length - 1,
1313
1699
  handler: (context) => context.undo(),
1314
1700
  },
@@ -1337,15 +1723,22 @@ const commands = [
1337
1723
  visible: true,
1338
1724
  active: (context) => context.root !== undefined && context.isSelection,
1339
1725
  handler: (context) => {
1340
- if (context.root === undefined)
1341
- return;
1726
+ if (context.root === undefined) return;
1342
1727
  // Save the copied content to the clipboard
1343
1728
  const copy = context.root.copyRange(context.range);
1344
- const edit = context.root.withRangeFormatted(context.range, undefined);
1345
- if (edit === undefined || copy === undefined)
1346
- return;
1729
+ const edit = context.root.withRangeFormatted(
1730
+ context.range,
1731
+ undefined
1732
+ );
1733
+ if (edit === undefined || copy === undefined) return;
1347
1734
  context.handleCopy(copy);
1348
- return rootWithNode(context, context.root, edit.root, () => edit.range.start);
1735
+
1736
+ return rootWithNode<RootNode>(
1737
+ context,
1738
+ context.root,
1739
+ edit.root as RootNode,
1740
+ () => edit.range.start
1741
+ );
1349
1742
  },
1350
1743
  },
1351
1744
  {
@@ -1360,12 +1753,10 @@ const commands = [
1360
1753
  visible: true,
1361
1754
  active: (context) => context.isSelection,
1362
1755
  handler: (context) => {
1363
- if (context.root === undefined)
1364
- return;
1756
+ if (context.root === undefined) return;
1365
1757
  // Save the copied content to the clipboard
1366
1758
  const copy = context.root.copyRange(context.range);
1367
- if (copy !== undefined)
1368
- context.handleCopy(copy);
1759
+ if (copy !== undefined) context.handleCopy(copy);
1369
1760
  return undefined;
1370
1761
  },
1371
1762
  },
@@ -1381,11 +1772,11 @@ const commands = [
1381
1772
  visible: true,
1382
1773
  active: () => true,
1383
1774
  handler: (context) => {
1384
- if (context.root === undefined)
1385
- return undefined;
1775
+ if (context.root === undefined) return undefined;
1776
+
1386
1777
  // See if there's something on the clipboard.
1387
1778
  if (navigator.clipboard) {
1388
- navigator.clipboard.read().then((items) => {
1779
+ navigator.clipboard.read().then((items: ClipboardItems) => {
1389
1780
  // If there's nothing, paste whatever is on the editor clipboard, if there is something.
1390
1781
  if (items.length === 0 && context.clipboard !== undefined)
1391
1782
  context.handlePaste(context, context.clipboard, true);
@@ -1396,27 +1787,37 @@ const commands = [
1396
1787
  if (item) {
1397
1788
  async function gatherClipboard() {
1398
1789
  // Eventually we should add HTML support.
1399
- const contents = {
1790
+ const contents: PasteContent = {
1400
1791
  plain: undefined,
1401
1792
  };
1402
1793
  try {
1403
1794
  {
1404
- const blob = await item.getType('text/plain');
1795
+ const blob = await item.getType(
1796
+ 'text/plain'
1797
+ );
1405
1798
  const text = await blob.text();
1406
1799
  contents.plain = text;
1407
1800
  }
1408
- context.handlePaste(context, contents, true);
1409
- }
1410
- catch (err) { }
1801
+ context.handlePaste(
1802
+ context,
1803
+ contents,
1804
+ true
1805
+ );
1806
+ } catch (err) {}
1411
1807
  }
1412
1808
  gatherClipboard();
1413
1809
  }
1414
1810
  // Otherwise, try pasting what's on the app clipboard.
1415
1811
  else if (context.clipboard !== undefined)
1416
- return context.handlePaste(context, context.clipboard, false);
1812
+ return context.handlePaste(
1813
+ context,
1814
+ context.clipboard,
1815
+ false
1816
+ );
1417
1817
  }
1418
1818
  });
1419
1819
  }
1820
+
1420
1821
  // Return the current caret to avoid unhandled command feedback.
1421
1822
  return { root: context.root, range: context.range };
1422
1823
  },
@@ -1432,7 +1833,8 @@ const commands = [
1432
1833
  shift: undefined,
1433
1834
  key: (key) => key.length === 1,
1434
1835
  visible: false,
1435
- active: (context, key) => context && key !== undefined && key.length === 1,
1836
+ active: (context, key) =>
1837
+ context && key !== undefined && key.length === 1,
1436
1838
  handler: (context, utilities, key) => {
1437
1839
  utilities;
1438
1840
  const range = context.range;
@@ -1440,49 +1842,62 @@ const commands = [
1440
1842
  // Insert at the start.
1441
1843
  let sortedRange = range.start.node.sortRange(range);
1442
1844
  let insertionPoint = sortedRange.start;
1443
- let newRoot = context.root;
1845
+ let newRoot: RootNode | undefined = context.root;
1846
+
1444
1847
  // Not a text node? Fail.
1445
- if (!(insertionPoint.node instanceof TextNode))
1446
- return;
1848
+ if (!(insertionPoint.node instanceof TextNode)) return;
1849
+
1447
1850
  // If there's a selection, remove it before inserting, and insert at the caret returned.
1448
1851
  if (context.isSelection) {
1449
1852
  if (context.code) {
1450
- if (context.code.getCodeNode() ===
1451
- sortedRange.start.node) {
1452
- const newText = insertionPoint.node.withoutRange(sortedRange);
1453
- if (newText === undefined)
1454
- return;
1455
- const edit = newRoot.withNodeReplaced(insertionPoint.node, newText);
1456
- if (edit === undefined)
1457
- return;
1853
+ if (
1854
+ context.code.getCodeNode() ===
1855
+ sortedRange.start.node
1856
+ ) {
1857
+ const newText =
1858
+ insertionPoint.node.withoutRange(sortedRange);
1859
+ if (newText === undefined) return;
1860
+ const edit = newRoot.withNodeReplaced(
1861
+ insertionPoint.node,
1862
+ newText
1863
+ );
1864
+ if (edit === undefined) return;
1458
1865
  newRoot = edit;
1459
1866
  insertionPoint = {
1460
1867
  node: newText,
1461
1868
  index: sortedRange.start.index,
1462
1869
  };
1463
1870
  }
1464
- }
1465
- else {
1871
+ } else {
1466
1872
  // Try to remove the range.
1467
- let edit = newRoot.withRangeFormatted(sortedRange, undefined);
1873
+ let edit = newRoot.withRangeFormatted(
1874
+ sortedRange,
1875
+ undefined
1876
+ );
1468
1877
  // If we fail, fail to insert at the selection.
1469
- if (edit === undefined)
1470
- return;
1471
- newRoot = edit.root;
1878
+ if (edit === undefined) return;
1879
+ newRoot = edit.root as RootNode;
1472
1880
  insertionPoint = edit.range.start;
1473
1881
  }
1474
1882
  }
1883
+
1475
1884
  // Not a text node? Fail.
1476
- if (!(insertionPoint.node instanceof TextNode))
1477
- return;
1885
+ if (!(insertionPoint.node instanceof TextNode)) return;
1886
+
1478
1887
  // Update the text node.
1479
- const newText = insertionPoint.node.withCharacterAt(key, insertionPoint.index);
1480
- if (newText === undefined)
1481
- return;
1888
+ const newText = insertionPoint.node.withCharacterAt(
1889
+ key,
1890
+ insertionPoint.index
1891
+ );
1892
+ if (newText === undefined) return;
1893
+
1482
1894
  // Replace the text.
1483
- newRoot = newRoot.withNodeReplaced(insertionPoint.node, newText);
1484
- if (newRoot === undefined)
1485
- return;
1895
+ newRoot = newRoot.withNodeReplaced(
1896
+ insertionPoint.node,
1897
+ newText
1898
+ );
1899
+ if (newRoot === undefined) return;
1900
+
1486
1901
  // Update the chapter
1487
1902
  return rootWithNode(context, context.root, newRoot, () => {
1488
1903
  return { node: newText, index: insertionPoint.index + 1 };