bookish-press 0.4.1 → 0.4.21

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 (395) hide show
  1. package/README.md +3 -1
  2. package/components/Auth.svelte +19 -14
  3. package/components/Auth.svelte.d.ts +4 -4
  4. package/components/Authentication.d.ts +2 -2
  5. package/components/BookPreview.svelte +77 -59
  6. package/components/BookPreview.svelte.d.ts +5 -5
  7. package/components/External.svelte +1 -1
  8. package/components/External.svelte.d.ts +3 -3
  9. package/components/Link.svelte +49 -3
  10. package/components/Link.svelte.d.ts +3 -4
  11. package/components/app/BookList.svelte +19 -0
  12. package/components/app/BookList.svelte.d.ts +18 -0
  13. package/components/app/Button.svelte +49 -0
  14. package/components/app/Button.svelte.d.ts +22 -0
  15. package/components/app/Feedback.svelte +45 -0
  16. package/components/app/Feedback.svelte.d.ts +18 -0
  17. package/components/app/Head.svelte +12 -0
  18. package/components/app/Head.svelte.d.ts +27 -0
  19. package/components/app/Large.svelte +8 -0
  20. package/components/app/Large.svelte.d.ts +27 -0
  21. package/components/app/Lead.svelte +12 -0
  22. package/components/app/Lead.svelte.d.ts +27 -0
  23. package/components/app/Link.svelte +24 -0
  24. package/components/app/Link.svelte.d.ts +20 -0
  25. package/components/app/Options.svelte +24 -0
  26. package/components/app/Options.svelte.d.ts +19 -0
  27. package/components/app/Paragraph.svelte +19 -0
  28. package/components/app/Paragraph.svelte.d.ts +18 -0
  29. package/components/app/Table.svelte +32 -0
  30. package/components/app/Table.svelte.d.ts +27 -0
  31. package/components/app/TextInput.svelte +37 -0
  32. package/components/app/TextInput.svelte.d.ts +22 -0
  33. package/components/app/Writing.svelte +13 -0
  34. package/components/app/Writing.svelte.d.ts +27 -0
  35. package/components/chapter/Atom.svelte +20 -6
  36. package/components/chapter/Atom.svelte.d.ts +3 -3
  37. package/components/chapter/Block.svelte +23 -20
  38. package/components/chapter/Block.svelte.d.ts +4 -4
  39. package/components/chapter/Callout.svelte +38 -7
  40. package/components/chapter/Callout.svelte.d.ts +4 -4
  41. package/components/chapter/CaptionedCode.svelte +66 -23
  42. package/components/chapter/CaptionedCode.svelte.d.ts +4 -4
  43. package/components/chapter/ChapterBody.svelte +61 -9
  44. package/components/chapter/ChapterBody.svelte.d.ts +4 -4
  45. package/components/chapter/Citations.svelte +86 -20
  46. package/components/chapter/Citations.svelte.d.ts +4 -4
  47. package/components/chapter/Code.svelte +152 -21
  48. package/components/chapter/Code.svelte.d.ts +3 -3
  49. package/components/chapter/Comment.svelte +38 -16
  50. package/components/chapter/Comment.svelte.d.ts +3 -3
  51. package/components/chapter/Definition.svelte +52 -18
  52. package/components/chapter/Definition.svelte.d.ts +5 -8
  53. package/components/chapter/Embed.svelte +154 -66
  54. package/components/chapter/Embed.svelte.d.ts +5 -4
  55. package/components/chapter/ErrorMessage.svelte +7 -2
  56. package/components/chapter/ErrorMessage.svelte.d.ts +4 -4
  57. package/components/chapter/ExtendedPrism.d.ts +2 -0
  58. package/components/chapter/ExtendedPrism.js +69 -0
  59. package/components/chapter/Figure.svelte +90 -0
  60. package/components/chapter/Figure.svelte.d.ts +24 -0
  61. package/components/chapter/Footnote.svelte +75 -12
  62. package/components/chapter/Footnote.svelte.d.ts +4 -4
  63. package/components/chapter/Format.svelte +60 -37
  64. package/components/chapter/Format.svelte.d.ts +4 -4
  65. package/components/chapter/InlineCode.svelte +15 -5
  66. package/components/chapter/InlineCode.svelte.d.ts +4 -4
  67. package/components/chapter/Label.svelte +37 -8
  68. package/components/chapter/Label.svelte.d.ts +4 -4
  69. package/components/chapter/Link.svelte +23 -18
  70. package/components/chapter/Link.svelte.d.ts +4 -4
  71. package/components/chapter/List.svelte +75 -8
  72. package/components/chapter/List.svelte.d.ts +4 -4
  73. package/components/chapter/Marginal.svelte +169 -27
  74. package/components/chapter/Marginal.svelte.d.ts +6 -3
  75. package/components/chapter/Paragraph.svelte +74 -6
  76. package/components/chapter/Paragraph.svelte.d.ts +4 -4
  77. package/components/chapter/Positioned.svelte +33 -0
  78. package/components/chapter/Positioned.svelte.d.ts +19 -0
  79. package/components/chapter/Problem.svelte +15 -0
  80. package/components/chapter/Problem.svelte.d.ts +27 -0
  81. package/components/chapter/Python.svelte +68 -21
  82. package/components/chapter/Python.svelte.d.ts +4 -4
  83. package/components/chapter/Quote.svelte +64 -11
  84. package/components/chapter/Quote.svelte.d.ts +4 -4
  85. package/components/chapter/Rule.svelte +12 -1
  86. package/components/chapter/Rule.svelte.d.ts +4 -4
  87. package/components/chapter/Table.svelte +36 -25
  88. package/components/chapter/Table.svelte.d.ts +4 -4
  89. package/components/chapter/Text.svelte +61 -36
  90. package/components/chapter/Text.svelte.d.ts +5 -4
  91. package/components/editor/BookishEditor.svelte +343 -237
  92. package/components/editor/BookishEditor.svelte.d.ts +5 -5
  93. package/components/editor/CalloutEditor.svelte +5 -5
  94. package/components/editor/CalloutEditor.svelte.d.ts +4 -4
  95. package/components/editor/CaptionedCodeEditor.svelte +16 -12
  96. package/components/editor/CaptionedCodeEditor.svelte.d.ts +4 -4
  97. package/components/editor/CaretContext.d.ts +48 -16
  98. package/components/editor/CaretState.d.ts +16 -44
  99. package/components/editor/CaretUtilities.d.ts +2 -2
  100. package/components/editor/CaretView.svelte +80 -0
  101. package/components/editor/CaretView.svelte.d.ts +24 -0
  102. package/components/editor/CitationsEditor.svelte +36 -25
  103. package/components/editor/CitationsEditor.svelte.d.ts +4 -4
  104. package/components/editor/Clipboard.d.ts +2 -2
  105. package/components/editor/Command.d.ts +13 -12
  106. package/components/editor/Commands.d.ts +1 -1
  107. package/components/editor/Commands.js +1114 -571
  108. package/components/editor/ConfirmButton.svelte +18 -12
  109. package/components/editor/ConfirmButton.svelte.d.ts +5 -4
  110. package/components/editor/DefinitionEditor.svelte +29 -21
  111. package/components/editor/DefinitionEditor.svelte.d.ts +4 -4
  112. package/components/editor/EmbedEditor.svelte +93 -43
  113. package/components/editor/EmbedEditor.svelte.d.ts +3 -3
  114. package/components/editor/Icon.svelte +17 -0
  115. package/components/editor/Icon.svelte.d.ts +16 -0
  116. package/components/editor/ImageChooser.svelte +53 -34
  117. package/components/editor/ImageChooser.svelte.d.ts +3 -3
  118. package/components/editor/InlineCodeEditor.svelte +7 -4
  119. package/components/editor/InlineCodeEditor.svelte.d.ts +4 -4
  120. package/components/editor/LabelEditor.svelte +20 -11
  121. package/components/editor/LabelEditor.svelte.d.ts +4 -4
  122. package/components/editor/LanguageEditor.svelte +10 -7
  123. package/components/editor/LanguageEditor.svelte.d.ts +3 -3
  124. package/components/editor/LinkEditor.svelte +64 -39
  125. package/components/editor/LinkEditor.svelte.d.ts +4 -4
  126. package/components/editor/Note.svelte +3 -3
  127. package/components/editor/Note.svelte.d.ts +6 -2
  128. package/components/editor/PositionEditor.svelte +9 -6
  129. package/components/editor/PositionEditor.svelte.d.ts +4 -4
  130. package/components/editor/QuoteEditor.svelte +7 -2
  131. package/components/editor/QuoteEditor.svelte.d.ts +4 -4
  132. package/components/editor/Switch.svelte +55 -28
  133. package/components/editor/Switch.svelte.d.ts +4 -4
  134. package/components/editor/TableEditor.svelte +10 -0
  135. package/components/editor/TableEditor.svelte.d.ts +17 -0
  136. package/components/editor/TextEditor.svelte +83 -45
  137. package/components/editor/TextEditor.svelte.d.ts +5 -4
  138. package/components/editor/Toggle.svelte +11 -8
  139. package/components/editor/Toggle.svelte.d.ts +4 -4
  140. package/components/editor/Toolbar.svelte +192 -144
  141. package/components/editor/Toolbar.svelte.d.ts +5 -8
  142. package/components/editor/ToolbarGroup.svelte +18 -23
  143. package/components/editor/ToolbarGroup.svelte.d.ts +3 -4
  144. package/components/editor/ToolbarSpacer.svelte +8 -1
  145. package/components/editor/ToolbarSpacer.svelte.d.ts +6 -2
  146. package/components/editor/URLEditor.svelte +6 -8
  147. package/components/editor/URLEditor.svelte.d.ts +3 -3
  148. package/components/editor/UndoState.d.ts +3 -3
  149. package/components/editor/icons/annotate.svg +1 -0
  150. package/components/editor/icons/block.svg +1 -0
  151. package/components/editor/icons/bold.svg +1 -0
  152. package/components/editor/icons/bullets.svg +1 -0
  153. package/components/editor/icons/callout.svg +1 -0
  154. package/components/editor/icons/citation.svg +8 -0
  155. package/components/editor/icons/clear.svg +1 -0
  156. package/components/editor/icons/clipboard.svg +1 -0
  157. package/components/editor/icons/code.svg +1 -0
  158. package/components/editor/icons/columnafter.svg +1 -0
  159. package/components/editor/icons/columnbefore.svg +1 -0
  160. package/components/editor/icons/comment.svg +1 -0
  161. package/components/editor/icons/copy.svg +1 -0
  162. package/components/editor/icons/cut.svg +1 -0
  163. package/components/editor/icons/define.svg +7 -0
  164. package/components/editor/icons/deletecolumn.svg +1 -0
  165. package/components/editor/icons/deleterow.svg +1 -0
  166. package/components/editor/icons/footnote.svg +8 -0
  167. package/components/editor/icons/header1.svg +7 -0
  168. package/components/editor/icons/header2.svg +7 -0
  169. package/components/editor/icons/header3.svg +7 -0
  170. package/components/editor/icons/home.svg +1 -0
  171. package/components/editor/icons/indent.svg +1 -0
  172. package/components/editor/icons/italic.svg +1 -0
  173. package/components/editor/icons/label.svg +1 -0
  174. package/components/editor/icons/left.svg +1 -0
  175. package/components/editor/icons/level.svg +1 -0
  176. package/components/editor/icons/link.svg +1 -0
  177. package/components/editor/icons/list.svg +1 -0
  178. package/components/editor/icons/media.svg +1 -0
  179. package/components/editor/icons/middle.svg +1 -0
  180. package/components/editor/icons/numbers.svg +10 -0
  181. package/components/editor/icons/paragraph.svg +1 -0
  182. package/components/editor/icons/paste.svg +10 -0
  183. package/components/editor/icons/quote.svg +1 -0
  184. package/components/editor/icons/redo.svg +1 -0
  185. package/components/editor/icons/right.svg +1 -0
  186. package/components/editor/icons/rowabove.svg +1 -0
  187. package/components/editor/icons/rowbelow.svg +1 -0
  188. package/components/editor/icons/rule.svg +1 -0
  189. package/components/editor/icons/sub.svg +1 -0
  190. package/components/editor/icons/super.svg +1 -0
  191. package/components/editor/icons/table.svg +1 -0
  192. package/components/editor/icons/text.svg +1 -0
  193. package/components/editor/icons/time.svg +1 -0
  194. package/components/editor/icons/undo.svg +1 -0
  195. package/components/editor/icons/unindent.svg +1 -0
  196. package/components/editor/icons/unlink.svg +1 -0
  197. package/components/page/Acknowledgements.svelte +31 -22
  198. package/components/page/Acknowledgements.svelte.d.ts +4 -4
  199. package/components/page/Authors.svelte +34 -14
  200. package/components/page/Authors.svelte.d.ts +6 -6
  201. package/components/page/BulkReferenceEditor.svelte +53 -22
  202. package/components/page/BulkReferenceEditor.svelte.d.ts +4 -4
  203. package/components/page/Chapter.svelte +196 -141
  204. package/components/page/Chapter.svelte.d.ts +3 -3
  205. package/components/page/ChapterContext.d.ts +4 -4
  206. package/components/page/ChapterNumber.svelte +9 -0
  207. package/components/page/ChapterNumber.svelte.d.ts +27 -0
  208. package/components/page/ChapterTitle.svelte +16 -0
  209. package/components/page/ChapterTitle.svelte.d.ts +18 -0
  210. package/components/page/Contexts.d.ts +31 -20
  211. package/components/page/Contexts.js +47 -17
  212. package/components/page/DefinitionView.svelte +115 -86
  213. package/components/page/DefinitionView.svelte.d.ts +3 -3
  214. package/components/page/Description.svelte +27 -18
  215. package/components/page/Description.svelte.d.ts +4 -4
  216. package/components/page/Edition.svelte +127 -75
  217. package/components/page/Edition.svelte.d.ts +4 -4
  218. package/components/page/Editions.svelte +158 -0
  219. package/components/page/Editions.svelte.d.ts +14 -0
  220. package/components/page/Glossary.svelte +57 -48
  221. package/components/page/Glossary.svelte.d.ts +4 -4
  222. package/components/page/Header.svelte +129 -44
  223. package/components/page/Header.svelte.d.ts +6 -6
  224. package/components/page/Index.svelte +114 -80
  225. package/components/page/Index.svelte.d.ts +4 -4
  226. package/components/page/Instructions.svelte +18 -16
  227. package/components/page/Instructions.svelte.d.ts +4 -4
  228. package/components/page/License.svelte +29 -21
  229. package/components/page/License.svelte.d.ts +4 -4
  230. package/components/page/Loading.svelte +102 -12
  231. package/components/page/Loading.svelte.d.ts +6 -2
  232. package/components/page/Media.svelte +77 -51
  233. package/components/page/Media.svelte.d.ts +4 -4
  234. package/components/page/MediaPreview.svelte +26 -8
  235. package/components/page/MediaPreview.svelte.d.ts +3 -3
  236. package/components/page/Muted.svelte +10 -0
  237. package/components/page/Muted.svelte.d.ts +27 -0
  238. package/components/page/Outline.svelte +279 -59
  239. package/components/page/Outline.svelte.d.ts +3 -3
  240. package/components/page/Page.svelte +40 -9
  241. package/components/page/Page.svelte.d.ts +3 -3
  242. package/components/page/PageHeader.svelte +14 -0
  243. package/components/page/PageHeader.svelte.d.ts +18 -0
  244. package/components/page/PageParagraph.svelte +18 -0
  245. package/components/page/PageParagraph.svelte.d.ts +27 -0
  246. package/components/page/PossibleChapter.svelte +7 -7
  247. package/components/page/PossibleChapter.svelte.d.ts +4 -4
  248. package/components/page/PossibleReference.svelte +6 -11
  249. package/components/page/PossibleReference.svelte.d.ts +6 -7
  250. package/components/page/Print.svelte +27 -3
  251. package/components/page/Print.svelte.d.ts +4 -4
  252. package/components/page/Reference.svelte +256 -113
  253. package/components/page/Reference.svelte.d.ts +5 -5
  254. package/components/page/References.svelte +39 -47
  255. package/components/page/References.svelte.d.ts +4 -4
  256. package/components/page/Rows.svelte +54 -0
  257. package/components/page/Rows.svelte.d.ts +27 -0
  258. package/components/page/Search.svelte +86 -63
  259. package/components/page/Search.svelte.d.ts +4 -4
  260. package/components/page/Status.svelte +43 -35
  261. package/components/page/Status.svelte.d.ts +4 -9
  262. package/components/page/SubdomainEditor.svelte +40 -27
  263. package/components/page/SubdomainEditor.svelte.d.ts +4 -4
  264. package/components/page/TableOfContents.svelte +225 -190
  265. package/components/page/TableOfContents.svelte.d.ts +4 -4
  266. package/components/page/TableOfContentsImage.svelte +8 -8
  267. package/components/page/TableOfContentsImage.svelte.d.ts +3 -3
  268. package/components/page/TableOfContentsRow.svelte +96 -33
  269. package/components/page/TableOfContentsRow.svelte.d.ts +4 -4
  270. package/components/page/ThemeEditor.svelte +174 -39
  271. package/components/page/ThemeEditor.svelte.d.ts +4 -4
  272. package/components/page/ThemeEditorPreview.svelte +35 -23
  273. package/components/page/ThemeEditorPreview.svelte.d.ts +5 -5
  274. package/components/page/ThemeSetEditor.svelte +15 -13
  275. package/components/page/ThemeSetEditor.svelte.d.ts +4 -4
  276. package/components/page/ThemeVariableEditor.svelte +24 -15
  277. package/components/page/ThemeVariableEditor.svelte.d.ts +3 -3
  278. package/components/page/Title.svelte +12 -0
  279. package/components/page/Title.svelte.d.ts +27 -0
  280. package/components/page/Unknown.svelte +25 -21
  281. package/components/page/Unknown.svelte.d.ts +4 -4
  282. package/components/page/margins.js +50 -33
  283. package/index.d.ts +14 -0
  284. package/index.js +14 -0
  285. package/models/CRUD.d.ts +17 -0
  286. package/models/CRUD.js +207 -0
  287. package/models/Firebase.d.ts +1 -0
  288. package/models/Firebase.js +21 -15
  289. package/models/book/Book.d.ts +26 -30
  290. package/models/book/Book.js +120 -113
  291. package/models/book/BookMedia.d.ts +3 -3
  292. package/models/book/BookMedia.js +22 -16
  293. package/models/book/BookSaveStatus.d.ts +7 -0
  294. package/models/book/BookSaveStatus.js +8 -0
  295. package/models/book/Chapter.d.ts +46 -39
  296. package/models/book/Chapter.js +180 -198
  297. package/models/book/ChapterID.js +7 -7
  298. package/models/book/Definition.d.ts +1 -1
  299. package/models/book/Edition.d.ts +62 -60
  300. package/models/book/Edition.js +385 -303
  301. package/models/book/Reference.d.ts +24 -0
  302. package/models/book/Reference.js +78 -0
  303. package/models/book/Schema.d.ts +169 -0
  304. package/models/book/Schema.js +114 -0
  305. package/models/book/Theme.d.ts +44 -37
  306. package/models/book/Theme.js +452 -52
  307. package/models/book/ThemeColors.d.ts +1 -1
  308. package/models/book/Words.d.ts +2 -0
  309. package/models/book/Words.js +110 -0
  310. package/models/chapter/AtomNode.d.ts +4 -4
  311. package/models/chapter/AtomNode.js +20 -13
  312. package/models/chapter/BlockNode.d.ts +9 -10
  313. package/models/chapter/BlockNode.js +32 -13
  314. package/models/chapter/BlocksNode.d.ts +10 -10
  315. package/models/chapter/BlocksNode.js +315 -120
  316. package/models/chapter/BlocksNode.test.js +494 -228
  317. package/models/chapter/Bookkeeping.d.ts +1 -1
  318. package/models/chapter/CalloutNode.d.ts +3 -3
  319. package/models/chapter/CalloutNode.js +34 -12
  320. package/models/chapter/Caret.d.ts +9 -7
  321. package/models/chapter/Caret.js +11 -6
  322. package/models/chapter/ChapterNode.d.ts +11 -11
  323. package/models/chapter/ChapterNode.js +70 -33
  324. package/models/chapter/CitationsNode.d.ts +3 -3
  325. package/models/chapter/CitationsNode.js +31 -12
  326. package/models/chapter/CodeNode.d.ts +11 -6
  327. package/models/chapter/CodeNode.js +143 -34
  328. package/models/chapter/CommentNode.d.ts +5 -5
  329. package/models/chapter/CommentNode.js +29 -13
  330. package/models/chapter/DefinitionNode.d.ts +2 -2
  331. package/models/chapter/DefinitionNode.js +15 -7
  332. package/models/chapter/Edit.d.ts +3 -3
  333. package/models/chapter/EmbedNode.d.ts +9 -5
  334. package/models/chapter/EmbedNode.js +108 -35
  335. package/models/chapter/ErrorNode.d.ts +2 -2
  336. package/models/chapter/ErrorNode.js +34 -12
  337. package/models/chapter/FootnoteNode.d.ts +5 -5
  338. package/models/chapter/FootnoteNode.js +34 -16
  339. package/models/chapter/FormatNode.d.ts +10 -10
  340. package/models/chapter/FormatNode.js +237 -106
  341. package/models/chapter/FormatNode.test.js +87 -45
  342. package/models/chapter/InlineCodeNode.d.ts +2 -2
  343. package/models/chapter/InlineCodeNode.js +22 -9
  344. package/models/chapter/LabelNode.d.ts +4 -4
  345. package/models/chapter/LabelNode.js +31 -13
  346. package/models/chapter/LinkNode.d.ts +2 -2
  347. package/models/chapter/LinkNode.js +21 -9
  348. package/models/chapter/ListNode.d.ts +8 -8
  349. package/models/chapter/ListNode.js +99 -38
  350. package/models/chapter/ListNode.test.js +29 -24
  351. package/models/chapter/MetadataNode.d.ts +3 -3
  352. package/models/chapter/MetadataNode.js +13 -5
  353. package/models/chapter/Node.d.ts +5 -3
  354. package/models/chapter/Node.js +76 -29
  355. package/models/chapter/Node.test.js +20 -18
  356. package/models/chapter/ParagraphNode.d.ts +6 -6
  357. package/models/chapter/ParagraphNode.js +84 -29
  358. package/models/chapter/ParagraphNode.test.js +22 -13
  359. package/models/chapter/Parser.d.ts +25 -25
  360. package/models/chapter/Parser.js +201 -189
  361. package/models/chapter/Parser.test.js +16 -16
  362. package/models/chapter/Position.d.ts +1 -1
  363. package/models/chapter/QuoteNode.d.ts +6 -6
  364. package/models/chapter/QuoteNode.js +61 -23
  365. package/models/chapter/RootNode.d.ts +4 -4
  366. package/models/chapter/RuleNode.d.ts +2 -2
  367. package/models/chapter/RuleNode.js +31 -11
  368. package/models/chapter/TableNode.d.ts +8 -6
  369. package/models/chapter/TableNode.js +89 -34
  370. package/models/chapter/TableNode.test.js +22 -24
  371. package/models/chapter/TextNode.d.ts +6 -6
  372. package/models/chapter/TextNode.js +72 -32
  373. package/models/chapter/TextNode.test.js +4 -4
  374. package/models/loadEdition.d.ts +1 -1
  375. package/models/loadEdition.js +10 -6
  376. package/package.json +104 -25
  377. package/util/getSubdomain.js +8 -6
  378. package/util/isMobile.js +1 -1
  379. package/util/mineReference.d.ts +3 -2
  380. package/util/mineReference.js +67 -29
  381. package/util/scrollToEyeLevel.js +6 -1
  382. package/components/chapter/renderPosition.d.ts +0 -3
  383. package/components/chapter/renderPosition.js +0 -4
  384. package/components/editor/ToolbarIcon.svelte +0 -22
  385. package/components/editor/ToolbarIcon.svelte.d.ts +0 -16
  386. package/components/page/Alert.svelte +0 -11
  387. package/components/page/Alert.svelte.d.ts +0 -23
  388. package/components/page/Revisions.svelte +0 -124
  389. package/components/page/Revisions.svelte.d.ts +0 -14
  390. package/models/BookLoader.d.ts +0 -2
  391. package/models/BookLoader.js +0 -67
  392. package/models/Firestore.d.ts +0 -22
  393. package/models/Firestore.js +0 -194
  394. package/models/chapter/ReferenceNode.d.ts +0 -29
  395. package/models/chapter/ReferenceNode.js +0 -48
@@ -1,54 +1,96 @@
1
1
  import { test, expect } from 'vitest';
2
- import FormatNode from "./FormatNode";
3
- import TextNode from "./TextNode";
4
- test("Bold first two characters", () => {
5
- const text = new TextNode("Hello");
6
- const format = new FormatNode("", [text]);
7
- expect(format.withFormat({ start: { node: text, index: 0 }, end: { node: text, index: 2 } }, "*")?.toBookdown()).toBe("*He*llo");
2
+ import FormatNode from './FormatNode';
3
+ import TextNode from './TextNode';
4
+ test('Bold first two characters', () => {
5
+ const text = new TextNode('Hello');
6
+ const format = new FormatNode('', [text]);
7
+ expect(format
8
+ .withFormat({
9
+ start: { node: text, index: 0 },
10
+ end: { node: text, index: 2 },
11
+ }, '*')
12
+ ?.toBookdown()).toBe('*He*llo');
8
13
  });
9
- test("Unbold word", () => {
10
- const text = new TextNode("Hello");
11
- const format = new FormatNode("", [new FormatNode("*", [text])]);
12
- expect(format.withFormat({ start: { node: text, index: 0 }, end: { node: text, index: 5 } }, "")?.toBookdown()).toBe("Hello");
14
+ test('Unbold word', () => {
15
+ const text = new TextNode('Hello');
16
+ const format = new FormatNode('', [new FormatNode('*', [text])]);
17
+ expect(format
18
+ .withFormat({
19
+ start: { node: text, index: 0 },
20
+ end: { node: text, index: 5 },
21
+ }, '')
22
+ ?.toBookdown()).toBe('Hello');
13
23
  });
14
- test("Bold single caret position", () => {
15
- const text = new TextNode("Hello");
16
- const format = new FormatNode("", [text]);
17
- expect(format.withFormat({ start: { node: text, index: 2 }, end: { node: text, index: 2 } }, "*")?.toBookdown()).toBe("He**llo");
24
+ test('Bold single caret position', () => {
25
+ const text = new TextNode('Hello');
26
+ const format = new FormatNode('', [text]);
27
+ expect(format
28
+ .withFormat({
29
+ start: { node: text, index: 2 },
30
+ end: { node: text, index: 2 },
31
+ }, '*')
32
+ ?.toBookdown()).toBe('He**llo');
18
33
  });
19
- test("Delete first two characters", () => {
20
- const text = new TextNode("Hello");
21
- const format = new FormatNode("", [text]);
22
- expect(format.withoutRange({ start: { node: text, index: 0 }, end: { node: text, index: 2 } })?.toBookdown()).toBe("llo");
34
+ test('Delete first two characters', () => {
35
+ const text = new TextNode('Hello');
36
+ const format = new FormatNode('', [text]);
37
+ expect(format
38
+ .withoutRange({
39
+ start: { node: text, index: 0 },
40
+ end: { node: text, index: 2 },
41
+ })
42
+ ?.toBookdown()).toBe('llo');
23
43
  });
24
- test("Delete characters crossing format boundary", () => {
25
- const text = new TextNode("He");
26
- const bolded = new TextNode("ll");
27
- const format = new FormatNode("", [text, new FormatNode("*", [bolded]), new TextNode("o")]);
28
- expect(format.withoutRange({ start: { node: text, index: 1 }, end: { node: bolded, index: 1 } })?.toBookdown()).toBe("H*l*o");
44
+ test('Delete characters crossing format boundary', () => {
45
+ const text = new TextNode('He');
46
+ const bolded = new TextNode('ll');
47
+ const format = new FormatNode('', [
48
+ text,
49
+ new FormatNode('*', [bolded]),
50
+ new TextNode('o'),
51
+ ]);
52
+ expect(format
53
+ .withoutRange({
54
+ start: { node: text, index: 1 },
55
+ end: { node: bolded, index: 1 },
56
+ })
57
+ ?.toBookdown()).toBe('H*l*o');
29
58
  });
30
- test("Split", () => {
31
- const text = new TextNode("This is my paragraph. It is two sentences.");
32
- const indexAfterPeriod = text.getText().indexOf(".") + 1;
59
+ test('Split', () => {
60
+ const text = new TextNode('This is my paragraph. It is two sentences.');
61
+ const indexAfterPeriod = text.getText().indexOf('.') + 1;
33
62
  const caret = { node: text, index: indexAfterPeriod };
34
- const format = new FormatNode("", [text]);
35
- expect(format.split(caret)?.map(t => t.toBookdown()).join("THEN")).toBe("This is my paragraph.THEN It is two sentences.");
63
+ const format = new FormatNode('', [text]);
64
+ expect(format
65
+ .split(caret)
66
+ ?.map((t) => t.toBookdown())
67
+ .join('THEN')).toBe('This is my paragraph.THEN It is two sentences.');
36
68
  });
37
- test("Backspace/delete", () => {
38
- const first = new TextNode("Hello, my name is ");
39
- const second = new TextNode("Amy");
40
- const third = new TextNode(".");
41
- const format = new FormatNode("", [first, new FormatNode("*", [second]), third]);
42
- expect(format.withoutCharacter({ node: first, index: 5 }, false)?.root.toBookdown())
43
- .toBe("Hell, my name is *Amy*.");
44
- expect(format.withoutCharacter({ node: first, index: 5 }, true)?.root.toBookdown())
45
- .toBe("Hello my name is *Amy*.");
46
- expect(format.withoutCharacter({ node: second, index: 0 }, false)?.root.toBookdown())
47
- .toBe("Hello, my name is*Amy*.");
48
- expect(format.withoutCharacter({ node: second, index: 0 }, true)?.root.toBookdown())
49
- .toBe("Hello, my name is *my*.");
50
- expect(format.withoutCharacter({ node: first, index: 0 }, false)?.root.toBookdown())
51
- .toBeUndefined();
52
- expect(format.withoutCharacter({ node: third, index: 1 }, true)?.root.toBookdown())
53
- .toBeUndefined();
69
+ test('Backspace/delete', () => {
70
+ const first = new TextNode('Hello, my name is ');
71
+ const second = new TextNode('Amy');
72
+ const third = new TextNode('.');
73
+ const format = new FormatNode('', [
74
+ first,
75
+ new FormatNode('*', [second]),
76
+ third,
77
+ ]);
78
+ expect(format
79
+ .withoutCharacter({ node: first, index: 5 }, false)
80
+ ?.root.toBookdown()).toBe('Hell, my name is *Amy*.');
81
+ expect(format
82
+ .withoutCharacter({ node: first, index: 5 }, true)
83
+ ?.root.toBookdown()).toBe('Hello my name is *Amy*.');
84
+ expect(format
85
+ .withoutCharacter({ node: second, index: 0 }, false)
86
+ ?.root.toBookdown()).toBe('Hello, my name is*Amy*.');
87
+ expect(format
88
+ .withoutCharacter({ node: second, index: 0 }, true)
89
+ ?.root.toBookdown()).toBe('Hello, my name is *my*.');
90
+ expect(format
91
+ .withoutCharacter({ node: first, index: 0 }, false)
92
+ ?.root.toBookdown()).toBeUndefined();
93
+ expect(format
94
+ .withoutCharacter({ node: third, index: 1 }, true)
95
+ ?.root.toBookdown()).toBeUndefined();
54
96
  });
@@ -1,5 +1,5 @@
1
- import MetadataNode from "./MetadataNode";
2
- import TextNode from "./TextNode";
1
+ import MetadataNode from './MetadataNode';
2
+ import TextNode from './TextNode';
3
3
  export default class InlineCodeNode extends MetadataNode<string> {
4
4
  constructor(code?: TextNode, language?: string);
5
5
  getType(): string;
@@ -1,18 +1,31 @@
1
- import MetadataNode from "./MetadataNode";
2
- import TextNode from "./TextNode";
1
+ import MetadataNode from './MetadataNode';
2
+ import TextNode from './TextNode';
3
3
  export default class InlineCodeNode extends MetadataNode {
4
- constructor(code, language = "plaintext") {
4
+ constructor(code, language = 'plaintext') {
5
5
  super(code === undefined ? new TextNode() : code, language);
6
6
  }
7
- getType() { return "inline-code"; }
7
+ getType() {
8
+ return 'inline-code';
9
+ }
8
10
  toText() {
9
11
  return this.getText().getText();
10
12
  }
11
- toHTML() { return `<code>${this.getMeta()}</code>`; }
13
+ toHTML() {
14
+ return `<code>${this.getMeta()}</code>`;
15
+ }
12
16
  toBookdown() {
13
- return "`" + this.getText().toBookdown().replace(/`/g, '\\`') + "`" + (this.getMeta() === "plaintext" ? "" : this.getMeta());
17
+ return ('`' +
18
+ this.getText().toBookdown().replace(/`/g, '\\`') +
19
+ '`' +
20
+ (this.getMeta() === 'plaintext' ? '' : this.getMeta()));
21
+ }
22
+ copy() {
23
+ return new InlineCodeNode(this.getText(), this.getMeta());
24
+ }
25
+ withMeta(meta) {
26
+ return new InlineCodeNode(this.getText(), meta);
27
+ }
28
+ withText(text) {
29
+ return new InlineCodeNode(text, this.getMeta());
14
30
  }
15
- copy() { return new InlineCodeNode(this.getText(), this.getMeta()); }
16
- withMeta(meta) { return new InlineCodeNode(this.getText(), meta); }
17
- withText(text) { return new InlineCodeNode(text, this.getMeta()); }
18
31
  }
@@ -1,7 +1,7 @@
1
- import AtomNode from "./AtomNode";
2
- import type Caret from "./Caret";
3
- import type FormatNode from "./FormatNode";
4
- import type Node from "./Node";
1
+ import AtomNode from './AtomNode';
2
+ import type Caret from './Caret';
3
+ import type FormatNode from './FormatNode';
4
+ import type Node from './Node';
5
5
  export default class LabelNode extends AtomNode<string> {
6
6
  constructor(newID: string);
7
7
  getType(): string;
@@ -1,22 +1,40 @@
1
- import AtomNode from "./AtomNode";
2
- const ERROR_PLACEHOLDER = "LABELNOIDERROR";
1
+ import AtomNode from './AtomNode';
2
+ const ERROR_PLACEHOLDER = 'LABELNOIDERROR';
3
3
  export default class LabelNode extends AtomNode {
4
4
  constructor(newID) {
5
- super(newID === ERROR_PLACEHOLDER ? "" : newID);
5
+ super(newID === ERROR_PLACEHOLDER ? '' : newID);
6
+ }
7
+ getType() {
8
+ return 'label';
9
+ }
10
+ getDefaultCaret() {
11
+ return { node: this, index: 0 };
12
+ }
13
+ toText() {
14
+ return '';
15
+ }
16
+ toHTML() {
17
+ return '';
6
18
  }
7
- getType() { return "label"; }
8
- getDefaultCaret() { return { node: this, index: 0 }; }
9
- toText() { return ""; }
10
- toHTML() { return ""; }
11
19
  toBookdown(format) {
12
20
  const id = this.getMeta();
13
21
  const nextText = format?.getNextTextOrAtom(this)?.toBookdown();
14
22
  // The trailing space after enables parsing. The error placeholder handles invalid empty label IDs.
15
- return `:${id === "" ? ERROR_PLACEHOLDER : id}${nextText?.startsWith(" ") ? "" : " "}`;
23
+ return `:${id === '' ? ERROR_PLACEHOLDER : id}${nextText?.startsWith(' ') ? '' : ' '}`;
24
+ }
25
+ getParentOf() {
26
+ return undefined;
27
+ }
28
+ copy() {
29
+ return new LabelNode(this.getMeta());
30
+ }
31
+ withMeta(newID) {
32
+ return new LabelNode(newID);
33
+ }
34
+ withChildReplaced() {
35
+ return undefined;
36
+ }
37
+ withContentInRange() {
38
+ return this.copy();
16
39
  }
17
- getParentOf() { return undefined; }
18
- copy() { return new LabelNode(this.getMeta()); }
19
- withMeta(newID) { return new LabelNode(newID); }
20
- withChildReplaced() { return undefined; }
21
- withContentInRange() { return this.copy(); }
22
40
  }
@@ -1,5 +1,5 @@
1
- import MetadataNode from "./MetadataNode";
2
- import TextNode from "./TextNode";
1
+ import MetadataNode from './MetadataNode';
2
+ import TextNode from './TextNode';
3
3
  export default class LinkNode extends MetadataNode<string> {
4
4
  constructor(text?: TextNode, url?: string);
5
5
  getType(): string;
@@ -1,16 +1,28 @@
1
- import MetadataNode from "./MetadataNode";
2
- import TextNode from "./TextNode";
1
+ import MetadataNode from './MetadataNode';
2
+ import TextNode from './TextNode';
3
3
  export default class LinkNode extends MetadataNode {
4
- constructor(text, url = "") {
4
+ constructor(text, url = '') {
5
5
  super(text === undefined ? new TextNode() : text, url);
6
6
  }
7
- getType() { return "link"; }
8
- toText() { return this.getText().toText(); }
9
- toHTML() { return `<a href="${this.getMeta()}">${this.getText().toHTML()}</a>`; }
10
- toBookdown() { return `[${this.getText().toBookdown()}|${this.getMeta()}]`; }
7
+ getType() {
8
+ return 'link';
9
+ }
10
+ toText() {
11
+ return this.getText().toText();
12
+ }
13
+ toHTML() {
14
+ return `<a href="${this.getMeta()}">${this.getText().toHTML()}</a>`;
15
+ }
16
+ toBookdown() {
17
+ return `[${this.getText().toBookdown()}|${this.getMeta()}]`;
18
+ }
11
19
  copy() {
12
20
  return new LinkNode(this.getText(), this.getMeta());
13
21
  }
14
- withMeta(meta) { return new LinkNode(this.getText(), meta); }
15
- withText(text) { return new LinkNode(text, this.getMeta()); }
22
+ withMeta(meta) {
23
+ return new LinkNode(this.getText(), meta);
24
+ }
25
+ withText(text) {
26
+ return new LinkNode(text, this.getMeta());
27
+ }
16
28
  }
@@ -1,11 +1,11 @@
1
- import type Node from "./Node";
2
- import FormatNode from "./FormatNode";
3
- import type { Format } from "./FormatNode";
4
- import type Caret from "./Caret";
5
- import { type CaretRange } from "./Caret";
6
- import BlockNode from "./BlockNode";
7
- import type Edit from "./Edit";
8
- export declare type ListNodeType = FormatNode | ListNode;
1
+ import type Node from './Node';
2
+ import FormatNode from './FormatNode';
3
+ import type { Format } from './FormatNode';
4
+ import type Caret from './Caret';
5
+ import { type CaretRange } from './Caret';
6
+ import BlockNode from './BlockNode';
7
+ import type Edit from './Edit';
8
+ export type ListNodeType = FormatNode | ListNode;
9
9
  export default class ListNode extends BlockNode {
10
10
  #private;
11
11
  constructor(items: Array<FormatNode | ListNode>, numbered: boolean);
@@ -1,6 +1,6 @@
1
- import FormatNode from "./FormatNode";
2
- import { caretToIndex, indexToCaret } from "./Caret";
3
- import BlockNode from "./BlockNode";
1
+ import FormatNode from './FormatNode';
2
+ import { caretToIndex, indexToCaret } from './Caret';
3
+ import BlockNode from './BlockNode';
4
4
  export default class ListNode extends BlockNode {
5
5
  #numbered;
6
6
  #items;
@@ -9,22 +9,43 @@ export default class ListNode extends BlockNode {
9
9
  this.#numbered = numbered;
10
10
  let adjustedItems = items
11
11
  // Make sure all format nodes have an empty text.
12
- .map(i => i instanceof FormatNode ? i.withTextIfEmpty() : i)
12
+ .map((i) => (i instanceof FormatNode ? i.withTextIfEmpty() : i))
13
13
  // Strip all empty sublists.
14
- .filter(i => !i.isEmpty());
14
+ .filter((i) => !i.isEmpty());
15
15
  this.#items = adjustedItems;
16
16
  }
17
- getType() { return "list"; }
18
- isNumbered() { return this.#numbered; }
19
- isEmpty() { return this.#items.length === 0 || this.#items.every(i => i instanceof ListNode && i.isEmpty()); }
20
- getItems() { return this.#items; }
21
- getChildren() { return this.#items; }
22
- getListItems() { return this.#items.filter(i => i instanceof ListNode); }
23
- getLength() { return this.#items.length; }
24
- getLastItem() { return this.getFirstLastItem(false); }
25
- getFirstItem() { return this.getFirstLastItem(true); }
17
+ getType() {
18
+ return 'list';
19
+ }
20
+ isNumbered() {
21
+ return this.#numbered;
22
+ }
23
+ isEmpty() {
24
+ return (this.#items.length === 0 ||
25
+ this.#items.every((i) => i instanceof ListNode && i.isEmpty()));
26
+ }
27
+ getItems() {
28
+ return this.#items;
29
+ }
30
+ getChildren() {
31
+ return this.#items;
32
+ }
33
+ getListItems() {
34
+ return this.#items.filter((i) => i instanceof ListNode);
35
+ }
36
+ getLength() {
37
+ return this.#items.length;
38
+ }
39
+ getLastItem() {
40
+ return this.getFirstLastItem(false);
41
+ }
42
+ getFirstItem() {
43
+ return this.getFirstLastItem(true);
44
+ }
26
45
  getFormats() {
27
- return this.#items.reduce((previous, current) => previous.concat(current instanceof FormatNode ? [current] : current.getFormats()), []);
46
+ return this.#items.reduce((previous, current) => previous.concat(current instanceof FormatNode
47
+ ? [current]
48
+ : current.getFormats()), []);
28
49
  }
29
50
  getFirstLastItem(first) {
30
51
  if (this.#items.length === 0)
@@ -44,30 +65,46 @@ export default class ListNode extends BlockNode {
44
65
  return 1;
45
66
  }
46
67
  toText() {
47
- return this.#items.map(item => item.toText()).join(" ");
68
+ return this.#items.map((item) => item.toText()).join(' ');
48
69
  }
49
70
  toBookdown(level = 1) {
50
- return this.isNumbered() ?
51
- this.#items.map((item, number) => (item instanceof ListNode ? "" : ((number + 1) + ".".repeat(level)) + " ") + item.toBookdown(level + 1)).join("\n") :
52
- this.#items.map(item => (item instanceof ListNode ? "" : "*".repeat(level) + " ") + item.toBookdown(level + 1)).join("\n");
71
+ return this.isNumbered()
72
+ ? this.#items
73
+ .map((item, number) => (item instanceof ListNode
74
+ ? ''
75
+ : number + 1 + '.'.repeat(level) + ' ') +
76
+ item.toBookdown(level + 1))
77
+ .join('\n')
78
+ : this.#items
79
+ .map((item) => (item instanceof ListNode
80
+ ? ''
81
+ : '*'.repeat(level) + ' ') +
82
+ item.toBookdown(level + 1))
83
+ .join('\n');
53
84
  }
54
85
  toHTML() {
55
- return this.isNumbered() ?
56
- `<ol>${this.#items.map(i => `<li>${i.toHTML()}</li>`).join("")}</ol>` :
57
- `<ul>${this.#items.map(i => `<li>${i.toHTML()}</li>`).join("")}</ul>`;
86
+ return this.isNumbered()
87
+ ? `<ol>${this.#items
88
+ .map((i) => `<li>${i.toHTML()}</li>`)
89
+ .join('')}</ol>`
90
+ : `<ul>${this.#items
91
+ .map((i) => `<li>${i.toHTML()}</li>`)
92
+ .join('')}</ul>`;
58
93
  }
59
94
  getParentOf(node) {
60
- return this.#items.map(b => b === node ? this : b.getParentOf(node)).find(b => b !== undefined);
95
+ return this.#items
96
+ .map((b) => (b === node ? this : b.getParentOf(node)))
97
+ .find((b) => b !== undefined);
61
98
  }
62
99
  atBeginningOfItem(root, caret) {
63
- const format = caret.node.getFarthestParentMatching(root, n => n instanceof FormatNode);
64
- return format !== undefined &&
100
+ const format = caret.node.getFarthestParentMatching(root, (n) => n instanceof FormatNode);
101
+ return (format !== undefined &&
65
102
  caret.node.hasAncestor(root, this) &&
66
103
  caret.index === 0 &&
67
- format.getTextNodes()[0] === caret.node;
104
+ format.getTextNodes()[0] === caret.node);
68
105
  }
69
106
  getItemContaining(caret) {
70
- const match = this.#items.find(n => n.getParentOf(caret.node) !== undefined);
107
+ const match = this.#items.find((n) => n.getParentOf(caret.node) !== undefined);
71
108
  if (match === undefined)
72
109
  return undefined;
73
110
  const index = this.#items.indexOf(match);
@@ -80,9 +117,13 @@ export default class ListNode extends BlockNode {
80
117
  return;
81
118
  return this.#items[index];
82
119
  }
83
- getFirstCaret() { return this.#items.length === 0 ? undefined : this.#items[0].getFirstCaret(); }
120
+ getFirstCaret() {
121
+ return this.#items.length === 0
122
+ ? undefined
123
+ : this.#items[0].getFirstCaret();
124
+ }
84
125
  copy() {
85
- return new ListNode(this.#items.map(i => i.copy()), this.#numbered);
126
+ return new ListNode(this.#items.map((i) => i.copy()), this.#numbered);
86
127
  }
87
128
  withStyle(numbered) {
88
129
  return new ListNode(this.#items, numbered);
@@ -211,14 +252,16 @@ export default class ListNode extends BlockNode {
211
252
  }
212
253
  withItemSplit(caret) {
213
254
  // Which item contains the caret?
214
- const item = this.#items.find(i => i instanceof FormatNode && i.contains(caret.node));
255
+ const item = this.#items.find((i) => i instanceof FormatNode && i.contains(caret.node));
215
256
  if (item === undefined)
216
257
  return;
217
258
  const parts = item.split(caret);
218
259
  if (parts === undefined)
219
260
  return;
220
261
  const [first, second] = parts;
221
- return this.withItemAfter(second, item)?.withItemAfter(first, item)?.withoutItem(item);
262
+ return this.withItemAfter(second, item)
263
+ ?.withItemAfter(first, item)
264
+ ?.withoutItem(item);
222
265
  }
223
266
  // Recursively search for the given item and indent it, constructing a new list.
224
267
  withItemIndented(format) {
@@ -283,9 +326,16 @@ export default class ListNode extends BlockNode {
283
326
  const index = this.#items.indexOf(node);
284
327
  if (index < 0)
285
328
  return;
286
- return new ListNode(replacement === undefined ?
287
- [...this.#items.slice(0, index), ...this.#items.slice(index + 1)] :
288
- [...this.#items.slice(0, index), replacement, ...this.#items.slice(index + 1)], this.#numbered);
329
+ return new ListNode(replacement === undefined
330
+ ? [
331
+ ...this.#items.slice(0, index),
332
+ ...this.#items.slice(index + 1),
333
+ ]
334
+ : [
335
+ ...this.#items.slice(0, index),
336
+ replacement,
337
+ ...this.#items.slice(index + 1),
338
+ ], this.#numbered);
289
339
  }
290
340
  withContentInRange(range) {
291
341
  const containsStart = this.contains(range.start.node);
@@ -316,7 +366,7 @@ export default class ListNode extends BlockNode {
316
366
  if (!(node instanceof ListNode))
317
367
  return;
318
368
  // Find the anchor item.
319
- const anchor = this.#items.find(i => i.contains(caret.node));
369
+ const anchor = this.#items.find((i) => i.contains(caret.node));
320
370
  if (anchor === undefined)
321
371
  return;
322
372
  const items = node.getItems();
@@ -343,7 +393,9 @@ export default class ListNode extends BlockNode {
343
393
  lastItem = item;
344
394
  }
345
395
  // The caret should be the last item inserted.
346
- const newCaret = lastItem instanceof FormatNode ? lastItem.getLastCaret() : lastItem.getLastItem()?.getLastCaret();
396
+ const newCaret = lastItem instanceof FormatNode
397
+ ? lastItem.getLastCaret()
398
+ : lastItem.getLastItem()?.getLastCaret();
347
399
  if (newCaret === undefined)
348
400
  return;
349
401
  return { root: newList, range: { start: newCaret, end: newCaret } };
@@ -352,9 +404,15 @@ export default class ListNode extends BlockNode {
352
404
  const sortedRange = this.sortRange(range);
353
405
  const itemStart = this.getItemContaining(sortedRange.start);
354
406
  const itemEnd = this.getItemContaining(sortedRange.end);
407
+ // This edits all of the formats contained in the range in the list, since the BlockNode class doesn't care about
408
+ // what formats are stored in.
355
409
  const edit = super.withRangeFormatted(sortedRange, format);
356
410
  // If we were deleting and two list items were involved, merge them.
357
- if (edit && format === undefined && itemStart !== undefined && itemEnd !== undefined && itemStart !== itemEnd) {
411
+ if (edit &&
412
+ format === undefined &&
413
+ itemStart !== undefined &&
414
+ itemEnd !== undefined &&
415
+ itemStart !== itemEnd) {
358
416
  const newList = edit.root;
359
417
  const itemIndex = itemEnd - (this.#items.length - newList.#items.length);
360
418
  if (itemIndex > 0 && newList.getLength() > 1) {
@@ -362,7 +420,10 @@ export default class ListNode extends BlockNode {
362
420
  const mergedEdit = newList.withItemMergedBackwards(itemIndex);
363
421
  if (mergedEdit === undefined)
364
422
  return;
365
- return { root: mergedEdit[0], range: { start: mergedEdit[1], end: mergedEdit[1] } };
423
+ return {
424
+ root: mergedEdit[0],
425
+ range: { start: mergedEdit[1], end: mergedEdit[1] },
426
+ };
366
427
  }
367
428
  }
368
429
  return edit;
@@ -1,48 +1,53 @@
1
1
  import { test, expect } from 'vitest';
2
- import FormatNode from "./FormatNode";
3
- import ListNode from "./ListNode";
4
- import TextNode from "./TextNode";
5
- const oneText = new TextNode("one");
6
- const oneFormat = new FormatNode("", [oneText]);
7
- const twoText = new TextNode("two");
8
- const twoFormat = new FormatNode("", [twoText]);
9
- const threeText = new TextNode("three");
10
- const threeFormat = new FormatNode("", [threeText]);
11
- const fourText = new TextNode("four");
12
- const fourFormat = new FormatNode("", [fourText]);
13
- const fiveText = new TextNode("five");
14
- const fiveFormat = new FormatNode("", [fiveText]);
2
+ import FormatNode from './FormatNode';
3
+ import ListNode from './ListNode';
4
+ import TextNode from './TextNode';
5
+ const oneText = new TextNode('one');
6
+ const oneFormat = new FormatNode('', [oneText]);
7
+ const twoText = new TextNode('two');
8
+ const twoFormat = new FormatNode('', [twoText]);
9
+ const threeText = new TextNode('three');
10
+ const threeFormat = new FormatNode('', [threeText]);
11
+ const fourText = new TextNode('four');
12
+ const fourFormat = new FormatNode('', [fourText]);
13
+ const fiveText = new TextNode('five');
14
+ const fiveFormat = new FormatNode('', [fiveText]);
15
15
  const shortList = new ListNode([oneFormat, twoFormat, threeFormat], false);
16
- const list = new ListNode([oneFormat, new ListNode([twoFormat, threeFormat, fourFormat], false), fiveFormat], false);
17
- test("Insert items", () => {
16
+ const list = new ListNode([
17
+ oneFormat,
18
+ new ListNode([twoFormat, threeFormat, fourFormat], false),
19
+ fiveFormat,
20
+ ], false);
21
+ test('Insert items', () => {
18
22
  expect(shortList.withItemAppended(fourFormat)?.toBookdown()).toBe(`* one\n* two\n* three\n* four`);
19
23
  expect(shortList.withItemPrepended(fourFormat)?.toBookdown()).toBe(`* four\n* one\n* two\n* three`);
20
24
  expect(shortList.withItemAt(fourFormat, 9)).toBeUndefined();
21
25
  expect(shortList.withItemAt(fourFormat, 1)?.toBookdown()).toBe(`* one\n* four\n* two\n* three`);
22
26
  expect(shortList.withItemAfter(fourFormat, oneFormat)?.toBookdown()).toBe(`* one\n* four\n* two\n* three`);
23
27
  expect(shortList.withItemBefore(fourFormat, twoFormat)?.toBookdown()).toBe(`* one\n* four\n* two\n* three`);
24
- expect(shortList.withListAppended(new ListNode([fourFormat, fiveFormat], true))?.toBookdown()).toBe(`* one\n* two\n* three\n* four\n* five`);
28
+ expect(shortList
29
+ .withListAppended(new ListNode([fourFormat, fiveFormat], true))
30
+ ?.toBookdown()).toBe(`* one\n* two\n* three\n* four\n* five`);
25
31
  });
26
- test("Remove items", () => {
32
+ test('Remove items', () => {
27
33
  expect(shortList.withItemReplaced(1, fourFormat)?.toBookdown()).toBe(`* one\n* four\n* three`);
28
34
  expect(shortList.withoutItemAt(0)?.toBookdown()).toBe(`* two\n* three`);
29
35
  });
30
- test("Split", () => {
31
- expect(shortList.withItemSplit({ node: threeText, index: 2 })?.toBookdown())
32
- .toBe("* one\n* two\n* th\n* ree");
36
+ test('Split', () => {
37
+ expect(shortList.withItemSplit({ node: threeText, index: 2 })?.toBookdown()).toBe('* one\n* two\n* th\n* ree');
33
38
  });
34
- test("Merge", () => {
39
+ test('Merge', () => {
35
40
  const merged = shortList.withItemMergedBackwards(1);
36
41
  expect(merged).not.toBeUndefined();
37
42
  if (merged !== undefined)
38
- expect(merged[0].toBookdown()).toBe("* onetwo\n* three");
43
+ expect(merged[0].toBookdown()).toBe('* onetwo\n* three');
39
44
  });
40
- test("Indent", () => {
45
+ test('Indent', () => {
41
46
  expect(list.withItemIndented(oneFormat)?.toBookdown()).toBe(`** one\n** two\n** three\n** four\n* five`);
42
47
  expect(list.withItemIndented(twoFormat)?.toBookdown()).toBe(`* one\n*** two\n** three\n** four\n* five`);
43
48
  expect(list.withItemIndented(fiveFormat)?.toBookdown()).toBe(`* one\n** two\n** three\n** four\n** five`);
44
49
  });
45
- test("Unindent", () => {
50
+ test('Unindent', () => {
46
51
  expect(list.withItemUnindented(twoFormat)?.toBookdown()).toBe(`* one\n* two\n** three\n** four\n* five`);
47
52
  expect(list.withItemUnindented(oneFormat)?.toBookdown()).toBeUndefined();
48
53
  expect(list.withItemUnindented(threeFormat)?.toBookdown()).toBe(`* one\n** two\n* three\n** four\n* five`);
@@ -1,6 +1,6 @@
1
- import type { CaretRange } from "./Caret";
2
- import Node from "./Node";
3
- import type TextNode from "./TextNode";
1
+ import type { CaretRange } from './Caret';
2
+ import Node from './Node';
3
+ import type TextNode from './TextNode';
4
4
  export default abstract class MetadataNode<MetaType> extends Node {
5
5
  #private;
6
6
  constructor(text: TextNode, meta: MetaType);