bookish-press 0.4.47 → 0.4.48

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