bookish-press 0.4.1 → 0.4.3

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 (403) hide show
  1. package/README.md +3 -1
  2. package/components/Auth.svelte +27 -24
  3. package/components/Auth.svelte.d.ts +4 -4
  4. package/components/Authentication.d.ts +2 -2
  5. package/components/BookPreview.svelte +75 -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 +47 -0
  16. package/components/app/Feedback.svelte.d.ts +18 -0
  17. package/components/app/Head.svelte +15 -0
  18. package/components/app/Head.svelte.d.ts +18 -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 +20 -0
  28. package/components/app/Paragraph.svelte.d.ts +18 -0
  29. package/components/app/Section.svelte +12 -0
  30. package/components/app/Section.svelte.d.ts +27 -0
  31. package/components/app/Table.svelte +32 -0
  32. package/components/app/Table.svelte.d.ts +27 -0
  33. package/components/app/TextInput.svelte +38 -0
  34. package/components/app/TextInput.svelte.d.ts +22 -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 +26 -21
  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 +67 -24
  42. package/components/chapter/CaptionedCode.svelte.d.ts +4 -4
  43. package/components/chapter/ChapterBody.svelte +62 -9
  44. package/components/chapter/ChapterBody.svelte.d.ts +5 -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 +39 -17
  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 +155 -67
  54. package/components/chapter/Embed.svelte.d.ts +6 -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 +63 -38
  64. package/components/chapter/Format.svelte.d.ts +5 -4
  65. package/components/chapter/InlineCode.svelte +16 -6
  66. package/components/chapter/InlineCode.svelte.d.ts +4 -4
  67. package/components/chapter/Label.svelte +38 -9
  68. package/components/chapter/Label.svelte.d.ts +4 -4
  69. package/components/chapter/Link.svelte +24 -19
  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 +79 -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 +373 -244
  92. package/components/editor/BookishEditor.svelte.d.ts +9 -6
  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 +82 -0
  101. package/components/editor/CaretView.svelte.d.ts +25 -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 +4 -3
  127. package/components/editor/Note.svelte.d.ts +6 -2
  128. package/components/editor/Permissions.svelte +95 -0
  129. package/components/editor/Permissions.svelte.d.ts +20 -0
  130. package/components/editor/PositionEditor.svelte +9 -6
  131. package/components/editor/PositionEditor.svelte.d.ts +4 -4
  132. package/components/editor/QuoteEditor.svelte +7 -2
  133. package/components/editor/QuoteEditor.svelte.d.ts +4 -4
  134. package/components/editor/Switch.svelte +55 -28
  135. package/components/editor/Switch.svelte.d.ts +4 -4
  136. package/components/editor/TableEditor.svelte +10 -0
  137. package/components/editor/TableEditor.svelte.d.ts +17 -0
  138. package/components/editor/TextEditor.svelte +83 -45
  139. package/components/editor/TextEditor.svelte.d.ts +5 -4
  140. package/components/editor/Toggle.svelte +11 -8
  141. package/components/editor/Toggle.svelte.d.ts +4 -4
  142. package/components/editor/Toolbar.svelte +191 -144
  143. package/components/editor/Toolbar.svelte.d.ts +5 -8
  144. package/components/editor/ToolbarGroup.svelte +17 -23
  145. package/components/editor/ToolbarGroup.svelte.d.ts +3 -4
  146. package/components/editor/ToolbarSpacer.svelte +8 -1
  147. package/components/editor/ToolbarSpacer.svelte.d.ts +6 -2
  148. package/components/editor/URLEditor.svelte +6 -8
  149. package/components/editor/URLEditor.svelte.d.ts +3 -3
  150. package/components/editor/UndoState.d.ts +3 -3
  151. package/components/editor/icons/annotate.svg +1 -0
  152. package/components/editor/icons/block.svg +1 -0
  153. package/components/editor/icons/bold.svg +1 -0
  154. package/components/editor/icons/bullets.svg +1 -0
  155. package/components/editor/icons/callout.svg +1 -0
  156. package/components/editor/icons/citation.svg +8 -0
  157. package/components/editor/icons/clear.svg +1 -0
  158. package/components/editor/icons/clipboard.svg +1 -0
  159. package/components/editor/icons/code.svg +1 -0
  160. package/components/editor/icons/columnafter.svg +1 -0
  161. package/components/editor/icons/columnbefore.svg +1 -0
  162. package/components/editor/icons/comment.svg +1 -0
  163. package/components/editor/icons/copy.svg +1 -0
  164. package/components/editor/icons/cut.svg +1 -0
  165. package/components/editor/icons/define.svg +7 -0
  166. package/components/editor/icons/deletecolumn.svg +1 -0
  167. package/components/editor/icons/deleterow.svg +1 -0
  168. package/components/editor/icons/footnote.svg +8 -0
  169. package/components/editor/icons/header1.svg +7 -0
  170. package/components/editor/icons/header2.svg +7 -0
  171. package/components/editor/icons/header3.svg +7 -0
  172. package/components/editor/icons/home.svg +1 -0
  173. package/components/editor/icons/indent.svg +1 -0
  174. package/components/editor/icons/italic.svg +1 -0
  175. package/components/editor/icons/label.svg +1 -0
  176. package/components/editor/icons/left.svg +1 -0
  177. package/components/editor/icons/level.svg +1 -0
  178. package/components/editor/icons/link.svg +1 -0
  179. package/components/editor/icons/list.svg +1 -0
  180. package/components/editor/icons/media.svg +1 -0
  181. package/components/editor/icons/middle.svg +1 -0
  182. package/components/editor/icons/numbers.svg +10 -0
  183. package/components/editor/icons/paragraph.svg +1 -0
  184. package/components/editor/icons/paste.svg +10 -0
  185. package/components/editor/icons/quote.svg +1 -0
  186. package/components/editor/icons/redo.svg +1 -0
  187. package/components/editor/icons/right.svg +1 -0
  188. package/components/editor/icons/rowabove.svg +1 -0
  189. package/components/editor/icons/rowbelow.svg +1 -0
  190. package/components/editor/icons/rule.svg +1 -0
  191. package/components/editor/icons/sub.svg +1 -0
  192. package/components/editor/icons/super.svg +1 -0
  193. package/components/editor/icons/table.svg +1 -0
  194. package/components/editor/icons/text.svg +1 -0
  195. package/components/editor/icons/time.svg +1 -0
  196. package/components/editor/icons/undo.svg +1 -0
  197. package/components/editor/icons/unindent.svg +1 -0
  198. package/components/editor/icons/unlink.svg +1 -0
  199. package/components/page/Acknowledgements.svelte +35 -24
  200. package/components/page/Acknowledgements.svelte.d.ts +4 -4
  201. package/components/page/Authors.svelte +34 -17
  202. package/components/page/Authors.svelte.d.ts +7 -6
  203. package/components/page/BookLoader.svelte +59 -0
  204. package/components/page/BookLoader.svelte.d.ts +16 -0
  205. package/components/page/BulkReferenceEditor.svelte +54 -23
  206. package/components/page/BulkReferenceEditor.svelte.d.ts +4 -4
  207. package/components/page/Chapter.svelte +234 -143
  208. package/components/page/Chapter.svelte.d.ts +3 -3
  209. package/components/page/ChapterContext.d.ts +4 -4
  210. package/components/page/ChapterNumber.svelte +9 -0
  211. package/components/page/ChapterNumber.svelte.d.ts +27 -0
  212. package/components/page/ChapterTitle.svelte +16 -0
  213. package/components/page/ChapterTitle.svelte.d.ts +18 -0
  214. package/components/page/Contexts.d.ts +42 -22
  215. package/components/page/Contexts.js +129 -17
  216. package/components/page/DefinitionView.svelte +129 -90
  217. package/components/page/DefinitionView.svelte.d.ts +3 -3
  218. package/components/page/Description.svelte +31 -19
  219. package/components/page/Description.svelte.d.ts +4 -4
  220. package/components/page/Edition.svelte +135 -81
  221. package/components/page/Edition.svelte.d.ts +5 -6
  222. package/components/page/EditionLoader.svelte +99 -0
  223. package/components/page/EditionLoader.svelte.d.ts +18 -0
  224. package/components/page/Editions.svelte +106 -0
  225. package/components/page/Editions.svelte.d.ts +14 -0
  226. package/components/page/Glossary.svelte +65 -49
  227. package/components/page/Glossary.svelte.d.ts +4 -4
  228. package/components/page/Header.svelte +143 -56
  229. package/components/page/Header.svelte.d.ts +8 -6
  230. package/components/page/Index.svelte +116 -80
  231. package/components/page/Index.svelte.d.ts +4 -4
  232. package/components/page/Instructions.svelte +18 -17
  233. package/components/page/Instructions.svelte.d.ts +6 -4
  234. package/components/page/License.svelte +39 -23
  235. package/components/page/License.svelte.d.ts +4 -4
  236. package/components/page/Loading.svelte +102 -12
  237. package/components/page/Loading.svelte.d.ts +6 -2
  238. package/components/page/Media.svelte +81 -53
  239. package/components/page/Media.svelte.d.ts +4 -4
  240. package/components/page/MediaPreview.svelte +26 -8
  241. package/components/page/MediaPreview.svelte.d.ts +3 -3
  242. package/components/page/Muted.svelte +10 -0
  243. package/components/page/Muted.svelte.d.ts +27 -0
  244. package/components/page/Outline.svelte +279 -59
  245. package/components/page/Outline.svelte.d.ts +3 -3
  246. package/components/page/Page.svelte +40 -9
  247. package/components/page/Page.svelte.d.ts +3 -3
  248. package/components/page/PageHeader.svelte +14 -0
  249. package/components/page/PageHeader.svelte.d.ts +18 -0
  250. package/components/page/PageParagraph.svelte +18 -0
  251. package/components/page/PageParagraph.svelte.d.ts +27 -0
  252. package/components/page/PossibleChapter.svelte +7 -7
  253. package/components/page/PossibleChapter.svelte.d.ts +4 -4
  254. package/components/page/PossibleReference.svelte +6 -11
  255. package/components/page/PossibleReference.svelte.d.ts +6 -7
  256. package/components/page/Print.svelte +27 -3
  257. package/components/page/Print.svelte.d.ts +4 -4
  258. package/components/page/Publish.svelte +134 -0
  259. package/components/page/Publish.svelte.d.ts +14 -0
  260. package/components/page/Reference.svelte +259 -117
  261. package/components/page/Reference.svelte.d.ts +5 -5
  262. package/components/page/References.svelte +45 -48
  263. package/components/page/References.svelte.d.ts +4 -4
  264. package/components/page/Rows.svelte +54 -0
  265. package/components/page/Rows.svelte.d.ts +27 -0
  266. package/components/page/Search.svelte +88 -63
  267. package/components/page/Search.svelte.d.ts +4 -4
  268. package/components/page/Status.svelte +46 -39
  269. package/components/page/Status.svelte.d.ts +4 -9
  270. package/components/page/SubdomainEditor.svelte +41 -27
  271. package/components/page/SubdomainEditor.svelte.d.ts +4 -4
  272. package/components/page/TableOfContents.svelte +264 -191
  273. package/components/page/TableOfContents.svelte.d.ts +4 -4
  274. package/components/page/TableOfContentsImage.svelte +8 -8
  275. package/components/page/TableOfContentsImage.svelte.d.ts +3 -3
  276. package/components/page/TableOfContentsRow.svelte +97 -34
  277. package/components/page/TableOfContentsRow.svelte.d.ts +4 -4
  278. package/components/page/ThemeEditor.svelte +177 -39
  279. package/components/page/ThemeEditor.svelte.d.ts +4 -4
  280. package/components/page/ThemeEditorPreview.svelte +35 -23
  281. package/components/page/ThemeEditorPreview.svelte.d.ts +5 -5
  282. package/components/page/ThemeSetEditor.svelte +15 -13
  283. package/components/page/ThemeSetEditor.svelte.d.ts +4 -4
  284. package/components/page/ThemeVariableEditor.svelte +24 -15
  285. package/components/page/ThemeVariableEditor.svelte.d.ts +3 -3
  286. package/components/page/Title.svelte +12 -0
  287. package/components/page/Title.svelte.d.ts +27 -0
  288. package/components/page/Unknown.svelte +28 -21
  289. package/components/page/Unknown.svelte.d.ts +4 -4
  290. package/components/page/margins.js +50 -33
  291. package/index.d.ts +13 -0
  292. package/index.js +14 -0
  293. package/models/CRUD.d.ts +27 -0
  294. package/models/CRUD.js +262 -0
  295. package/models/Firebase.d.ts +1 -0
  296. package/models/Firebase.js +26 -16
  297. package/models/book/Book.d.ts +40 -39
  298. package/models/book/Book.js +121 -121
  299. package/models/book/BookMedia.d.ts +3 -3
  300. package/models/book/BookMedia.js +22 -16
  301. package/models/book/BookSaveStatus.d.ts +7 -0
  302. package/models/book/BookSaveStatus.js +8 -0
  303. package/models/book/Chapter.d.ts +50 -39
  304. package/models/book/Chapter.js +189 -198
  305. package/models/book/ChapterID.js +7 -7
  306. package/models/book/Definition.d.ts +1 -1
  307. package/models/book/Edition.d.ts +87 -61
  308. package/models/book/Edition.js +460 -309
  309. package/models/book/Reference.d.ts +24 -0
  310. package/models/book/Reference.js +78 -0
  311. package/models/book/Schema.d.ts +168 -0
  312. package/models/book/Schema.js +115 -0
  313. package/models/book/Theme.d.ts +44 -37
  314. package/models/book/Theme.js +452 -52
  315. package/models/book/ThemeColors.d.ts +1 -1
  316. package/models/book/Words.d.ts +2 -0
  317. package/models/book/Words.js +110 -0
  318. package/models/chapter/AtomNode.d.ts +4 -4
  319. package/models/chapter/AtomNode.js +20 -13
  320. package/models/chapter/BlockNode.d.ts +9 -10
  321. package/models/chapter/BlockNode.js +32 -13
  322. package/models/chapter/BlocksNode.d.ts +10 -10
  323. package/models/chapter/BlocksNode.js +315 -120
  324. package/models/chapter/BlocksNode.test.js +494 -228
  325. package/models/chapter/Bookkeeping.d.ts +1 -1
  326. package/models/chapter/CalloutNode.d.ts +3 -3
  327. package/models/chapter/CalloutNode.js +34 -12
  328. package/models/chapter/Caret.d.ts +9 -7
  329. package/models/chapter/Caret.js +11 -6
  330. package/models/chapter/ChapterNode.d.ts +11 -11
  331. package/models/chapter/ChapterNode.js +70 -33
  332. package/models/chapter/CitationsNode.d.ts +3 -3
  333. package/models/chapter/CitationsNode.js +31 -12
  334. package/models/chapter/CodeNode.d.ts +11 -6
  335. package/models/chapter/CodeNode.js +143 -34
  336. package/models/chapter/CommentNode.d.ts +5 -5
  337. package/models/chapter/CommentNode.js +29 -13
  338. package/models/chapter/DefinitionNode.d.ts +2 -2
  339. package/models/chapter/DefinitionNode.js +15 -7
  340. package/models/chapter/Edit.d.ts +3 -3
  341. package/models/chapter/EmbedNode.d.ts +9 -5
  342. package/models/chapter/EmbedNode.js +108 -35
  343. package/models/chapter/ErrorNode.d.ts +2 -2
  344. package/models/chapter/ErrorNode.js +34 -12
  345. package/models/chapter/FootnoteNode.d.ts +5 -5
  346. package/models/chapter/FootnoteNode.js +34 -16
  347. package/models/chapter/FormatNode.d.ts +10 -10
  348. package/models/chapter/FormatNode.js +237 -106
  349. package/models/chapter/FormatNode.test.js +87 -45
  350. package/models/chapter/InlineCodeNode.d.ts +2 -2
  351. package/models/chapter/InlineCodeNode.js +22 -9
  352. package/models/chapter/LabelNode.d.ts +4 -4
  353. package/models/chapter/LabelNode.js +31 -13
  354. package/models/chapter/LinkNode.d.ts +2 -2
  355. package/models/chapter/LinkNode.js +21 -9
  356. package/models/chapter/ListNode.d.ts +8 -8
  357. package/models/chapter/ListNode.js +99 -38
  358. package/models/chapter/ListNode.test.js +29 -24
  359. package/models/chapter/MetadataNode.d.ts +3 -3
  360. package/models/chapter/MetadataNode.js +13 -5
  361. package/models/chapter/Node.d.ts +5 -3
  362. package/models/chapter/Node.js +76 -29
  363. package/models/chapter/Node.test.js +20 -18
  364. package/models/chapter/ParagraphNode.d.ts +6 -6
  365. package/models/chapter/ParagraphNode.js +84 -29
  366. package/models/chapter/ParagraphNode.test.js +22 -13
  367. package/models/chapter/Parser.d.ts +27 -27
  368. package/models/chapter/Parser.js +220 -206
  369. package/models/chapter/Parser.test.js +16 -16
  370. package/models/chapter/Position.d.ts +1 -1
  371. package/models/chapter/QuoteNode.d.ts +6 -6
  372. package/models/chapter/QuoteNode.js +61 -23
  373. package/models/chapter/RootNode.d.ts +4 -4
  374. package/models/chapter/RuleNode.d.ts +2 -2
  375. package/models/chapter/RuleNode.js +31 -11
  376. package/models/chapter/TableNode.d.ts +8 -6
  377. package/models/chapter/TableNode.js +89 -34
  378. package/models/chapter/TableNode.test.js +22 -24
  379. package/models/chapter/TextNode.d.ts +6 -6
  380. package/models/chapter/TextNode.js +72 -32
  381. package/models/chapter/TextNode.test.js +4 -4
  382. package/package.json +108 -26
  383. package/util/getSubdomain.js +8 -6
  384. package/util/isMobile.js +1 -1
  385. package/util/mineReference.d.ts +3 -2
  386. package/util/mineReference.js +67 -29
  387. package/util/scrollToEyeLevel.js +6 -1
  388. package/components/chapter/renderPosition.d.ts +0 -3
  389. package/components/chapter/renderPosition.js +0 -4
  390. package/components/editor/ToolbarIcon.svelte +0 -22
  391. package/components/editor/ToolbarIcon.svelte.d.ts +0 -16
  392. package/components/page/Alert.svelte +0 -11
  393. package/components/page/Alert.svelte.d.ts +0 -23
  394. package/components/page/Revisions.svelte +0 -124
  395. package/components/page/Revisions.svelte.d.ts +0 -14
  396. package/models/BookLoader.d.ts +0 -2
  397. package/models/BookLoader.js +0 -67
  398. package/models/Firestore.d.ts +0 -22
  399. package/models/Firestore.js +0 -194
  400. package/models/chapter/ReferenceNode.d.ts +0 -29
  401. package/models/chapter/ReferenceNode.js +0 -48
  402. package/models/loadEdition.d.ts +0 -5
  403. package/models/loadEdition.js +0 -16
@@ -0,0 +1,27 @@
1
+ /** @typedef {typeof __propDef.props} TitleProps */
2
+ /** @typedef {typeof __propDef.events} TitleEvents */
3
+ /** @typedef {typeof __propDef.slots} TitleSlots */
4
+ export default class Title extends SvelteComponentTyped<{
5
+ [x: string]: never;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {
9
+ default: {};
10
+ }> {
11
+ }
12
+ export type TitleProps = typeof __propDef.props;
13
+ export type TitleEvents = typeof __propDef.events;
14
+ export type TitleSlots = typeof __propDef.slots;
15
+ import { SvelteComponentTyped } from "svelte";
16
+ declare const __propDef: {
17
+ props: {
18
+ [x: string]: never;
19
+ };
20
+ events: {
21
+ [evt: string]: CustomEvent<any>;
22
+ };
23
+ slots: {
24
+ default: {};
25
+ };
26
+ };
27
+ export {};
@@ -1,29 +1,36 @@
1
- <script>import Header from "./Header.svelte";
1
+ <script>import Header from './Header.svelte';
2
2
  import Outline from './Outline.svelte';
3
3
  import Page from './Page.svelte';
4
4
  import Instructions from './Instructions.svelte';
5
5
  import ChapterIDs from '../../models/book/ChapterID';
6
- import { getEdition } from "./Contexts";
6
+ import { getEdition, isEditionEditable } from './Contexts';
7
+ let editable = isEditionEditable();
7
8
  let edition = getEdition();
8
9
  </script>
9
- <Page title={`${$edition.getTitle()} - Unknown Page`}>
10
- <Header
11
- label="Unknown page title"
12
- getImage={() => $edition.getImage(ChapterIDs.UnknownID)}
13
- setImage={embed => $edition.setImage(ChapterIDs.UnknownID, embed)}
14
- header="Oops."
15
- >
16
- <Outline
17
- slot="outline"
18
- previous={null}
19
- next={null}
20
- />
21
- </Header>
22
10
 
23
- <Instructions>
24
- This page will be shown if the reader somehow ends up on a page that doesn't exist.
25
- You can customize the image shown.
26
- </Instructions>
11
+ {#if $edition}
12
+ <Page title={`${$edition.getTitle()} - Unknown Page`}>
13
+ <Header
14
+ editable={isEditionEditable()}
15
+ label="Unknown page title"
16
+ id="unknown"
17
+ getImage={() => $edition?.getImage(ChapterIDs.UnknownID) ?? null}
18
+ setImage={(embed) =>
19
+ $edition
20
+ ? edition.set(
21
+ $edition.withImage(ChapterIDs.UnknownID, embed)
22
+ )
23
+ : undefined}
24
+ header="Oops."
25
+ >
26
+ <Outline slot="outline" previous={null} next={null} />
27
+ </Header>
27
28
 
28
- <slot></slot>
29
- </Page>
29
+ <Instructions {editable}>
30
+ This page will be shown if the reader somehow ends up on a page that
31
+ doesn't exist. You can customize the image shown.
32
+ </Instructions>
33
+
34
+ <slot />
35
+ </Page>
36
+ {/if}
@@ -1,6 +1,6 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
- props: {};
3
+ props: Record<string, never>;
4
4
  events: {
5
5
  [evt: string]: CustomEvent<any>;
6
6
  };
@@ -8,9 +8,9 @@ declare const __propDef: {
8
8
  default: {};
9
9
  };
10
10
  };
11
- export declare type UnknownProps = typeof __propDef.props;
12
- export declare type UnknownEvents = typeof __propDef.events;
13
- export declare type UnknownSlots = typeof __propDef.slots;
11
+ export type UnknownProps = typeof __propDef.props;
12
+ export type UnknownEvents = typeof __propDef.events;
13
+ export type UnknownSlots = typeof __propDef.slots;
14
14
  export default class Unknown extends SvelteComponentTyped<UnknownProps, UnknownEvents, UnknownSlots> {
15
15
  }
16
16
  export {};
@@ -2,18 +2,18 @@
2
2
  // This operates on the DOM directly, as scroll position isn't easily managed in React.
3
3
  export function hideOutlineIfObscured() {
4
4
  // Get the outline's bounds.
5
- let outline = document.getElementsByClassName("bookish-outline")[0];
5
+ let outline = document.getElementsByClassName('outline')[0];
6
6
  // If there's no outline, don't bother.
7
7
  if (!outline)
8
8
  return;
9
9
  // Set a threshold for hiding
10
10
  let threshold = 100;
11
11
  // If the outline isn't affixed to the footer
12
- if (window.getComputedStyle(outline).getPropertyValue("left") !== "0px") {
12
+ if (window.getComputedStyle(outline).getPropertyValue('left') !== '0px') {
13
13
  let outlineRect = outline.getBoundingClientRect();
14
14
  let overlapRect = undefined;
15
15
  // Find the bottom-most left inset marginal within threshold of the outline.
16
- Array.from(document.getElementsByClassName("bookish-marginal-left-inset")).forEach(el => {
16
+ Array.from(document.getElementsByClassName('inset-left')).forEach((el) => {
17
17
  let insetRect = el.getBoundingClientRect();
18
18
  if (!(outlineRect.bottom < insetRect.top - threshold ||
19
19
  outlineRect.top > insetRect.bottom + threshold))
@@ -22,24 +22,28 @@ export function hideOutlineIfObscured() {
22
22
  // If it overlaps, reduce opacity by the proportion of the vertical distance between two rectangles and the height of the marginal.
23
23
  if (overlapRect) {
24
24
  let overlap = overlapRect;
25
- let distance = outlineRect.bottom < overlap.top ? threshold :
26
- outlineRect.bottom < overlap.top + threshold ? threshold - (outlineRect.bottom - overlap.top) :
27
- outlineRect.top > overlap.bottom - threshold ? threshold - (overlap.bottom - outlineRect.top) :
28
- outlineRect.top > overlap.bottom ? threshold :
29
- 0;
25
+ let distance = outlineRect.bottom < overlap.top
26
+ ? threshold
27
+ : outlineRect.bottom < overlap.top + threshold
28
+ ? threshold - (outlineRect.bottom - overlap.top)
29
+ : outlineRect.top > overlap.bottom - threshold
30
+ ? threshold - (overlap.bottom - outlineRect.top)
31
+ : outlineRect.top > overlap.bottom
32
+ ? threshold
33
+ : 0;
30
34
  let proportion = distance / threshold;
31
- outline.style.opacity = "" + (proportion * proportion);
35
+ outline.style.opacity = '' + proportion * proportion;
32
36
  }
33
37
  // Otherwise, remove the dimming.
34
38
  else
35
- outline.style.removeProperty("opacity");
39
+ outline.style.removeProperty('opacity');
36
40
  }
37
41
  // If it is, it's always visible.
38
42
  else
39
- outline.style.removeProperty("opacity");
43
+ outline.style.removeProperty('opacity');
40
44
  }
41
45
  // After each render of the chapter, we need to adjust the layout of marginals, which by default are floating from
42
- // their little spans within the body of the text.
46
+ // their little spans within the body of the text.
43
47
  //
44
48
  // We have to do two things:
45
49
  //
@@ -50,53 +54,60 @@ export function hideOutlineIfObscured() {
50
54
  // fixed in a fixed position.
51
55
  export function layoutMarginals() {
52
56
  // Get the chapter DOM node, so we can calculate margins.
53
- let chapter = document.getElementsByClassName("bookish-chapter-body")[0];
57
+ let chapter = document.getElementsByClassName('bookish-chapter-body')[0];
54
58
  // If there's no chapter rendered yet, stop.
55
59
  if (chapter === undefined)
56
60
  return;
57
- let book = document.getElementsByClassName("bookish")[0];
61
+ let book = document.getElementsByClassName('bookish')[0];
58
62
  // This is the grid line we'll aline all marginals too horizontally.
59
63
  let margin = chapter.getBoundingClientRect().width;
60
64
  // This will track the current leading bottom edge for laying out marginals.
61
65
  let currentBottom = null;
62
66
  // Are there any marginal right inset images that might overlap?
63
- let rightInsets = document.getElementsByClassName("bookish-marginal-right-inset");
64
- const marginals = document.getElementsByClassName("bookish-marginal");
67
+ let rightInsets = document.getElementsByClassName('inset-right');
68
+ const marginals = document.getElementsByClassName('bookish-marginal');
65
69
  // Layout all of the marginals vertically to prevent overlaps.
66
70
  Array.from(marginals).forEach((element) => {
67
71
  const el = element;
68
72
  if (el === null)
69
73
  return;
70
- if (window.getComputedStyle(el).getPropertyValue("position") !== "fixed") {
74
+ if (window.getComputedStyle(el).getPropertyValue('position') !== 'fixed') {
71
75
  if (el.parentElement) {
72
- let containingMarginal = el.parentElement.closest(".bookish-marginal");
76
+ let containingMarginal = el.parentElement.closest('.bookish-marginal');
73
77
  // Get the bounds of this marginal so we know it's size.
74
78
  let elementBounds = el.getBoundingClientRect();
75
79
  // Get the bounds of this marginal's parent so we know it's vertical position.
76
80
  let parentBounds = el.parentElement.getBoundingClientRect();
77
- let parentTop = parentBounds.top + window.scrollY - (book.getBoundingClientRect().top + window.scrollY);
81
+ let parentTop = parentBounds.top +
82
+ window.scrollY -
83
+ (book.getBoundingClientRect().top + window.scrollY);
78
84
  // If it's inside a marginal, position it below the marginal.
79
85
  if (containingMarginal !== null && currentBottom) {
80
- el.style.left = "0";
81
- el.style.top = "" + (currentBottom - (containingMarginal.getBoundingClientRect().top + window.scrollY)) + "px";
86
+ el.style.left = '0';
87
+ el.style.top =
88
+ '' +
89
+ (currentBottom -
90
+ (containingMarginal.getBoundingClientRect().top +
91
+ window.scrollY)) +
92
+ 'px';
82
93
  currentBottom = currentBottom + elementBounds.height;
83
94
  }
84
95
  else {
85
96
  // If we don't have a bottom yet, or the current above is above the parent's top,
86
97
  // then set the current bottom to the bottom of the parent.
87
98
  if (currentBottom === null || currentBottom < parentTop) {
88
- el.style.top = parentTop + "px";
99
+ el.style.top = parentTop + 'px';
89
100
  currentBottom = parentTop + elementBounds.height;
90
101
  }
91
102
  // Otherwise, put the marginal below the last marginal's bottom.
92
103
  else {
93
- el.style.top = currentBottom + "px";
104
+ el.style.top = currentBottom + 'px';
94
105
  currentBottom = currentBottom + elementBounds.height;
95
106
  }
96
107
  // If there are any right insets, do any intersect with this marginal?
97
108
  // If so, move the marginal below them.
98
109
  if (rightInsets.length > 0) {
99
- Array.from(rightInsets).forEach(inset => {
110
+ Array.from(rightInsets).forEach((inset) => {
100
111
  // Compute the global positions of the marginal and the potential inset.
101
112
  let insetBounds = inset.getBoundingClientRect();
102
113
  let insetTop = insetBounds.top + window.scrollY;
@@ -105,28 +116,34 @@ export function layoutMarginals() {
105
116
  let elementBottom = elementTop + elementBounds.height;
106
117
  // If they overlap...
107
118
  if (currentBottom !== null) {
108
- if ((elementTop <= insetTop && elementBottom >= insetTop) ||
109
- (elementTop <= insetBottom && elementBottom >= insetBottom) ||
110
- (elementTop >= insetTop && elementBottom <= insetBottom)) {
119
+ if ((elementTop <= insetTop &&
120
+ elementBottom >= insetTop) ||
121
+ (elementTop <= insetBottom &&
122
+ elementBottom >= insetBottom) ||
123
+ (elementTop >= insetTop &&
124
+ elementBottom <= insetBottom)) {
111
125
  // Calculate the new position based on the preferred position, minus the element's height (which was added above), plus the overlap between the inset and the marginal.
112
- let newTop = currentBottom - elementBounds.height + (insetBottom - elementTop);
126
+ let newTop = currentBottom -
127
+ elementBounds.height +
128
+ (insetBottom - elementTop);
113
129
  // Reposition the marginal.
114
- el.style.top = newTop + "px";
130
+ el.style.top = newTop + 'px';
115
131
  // Update the new bottom.
116
- currentBottom = newTop + elementBounds.height;
132
+ currentBottom =
133
+ newTop + elementBounds.height;
117
134
  }
118
135
  }
119
136
  });
120
137
  }
121
138
  // Reposition the marginal horizontally.
122
- el.style.left = "calc(2rem + " + margin + "px)";
139
+ el.style.left = 'calc(2rem + ' + margin + 'px)';
123
140
  }
124
141
  }
125
142
  }
126
143
  // If it's fixed, remove any explicitly set inline values.
127
144
  else {
128
- el.style.removeProperty("top");
129
- el.style.removeProperty("left");
145
+ el.style.removeProperty('top');
146
+ el.style.removeProperty('left');
130
147
  }
131
148
  });
132
149
  }
package/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export { default as TableOfContents } from "./components/page/TableOfContents.svelte";
2
+ export { default as Search } from "./components/page/Search.svelte";
3
+ export { default as Index } from "./components/page/Index.svelte";
4
+ export { default as References } from "./components/page/References.svelte";
5
+ export { default as PossibleChapter } from "./components/page/PossibleChapter.svelte";
6
+ export { default as Media } from "./components/page/Media.svelte";
7
+ export { default as Print } from "./components/page/Print.svelte";
8
+ export { default as Glossary } from "./components/page/Glossary.svelte";
9
+ export { default as Edition } from "./components/page/Edition.svelte";
10
+ export { default as Feedback } from "./components/app/Feedback.svelte";
11
+ export { default as Loading } from "./components/page/Loading.svelte";
12
+ export { default as EditionModel } from "./models/book/Edition";
13
+ export { EDITION } from "./components/page/Contexts";
package/index.js ADDED
@@ -0,0 +1,14 @@
1
+ export { default as TableOfContents } from './components/page/TableOfContents.svelte';
2
+ export { default as Search } from './components/page/Search.svelte';
3
+ export { default as Index } from './components/page/Index.svelte';
4
+ export { default as References } from './components/page/References.svelte';
5
+ export { default as PossibleChapter } from './components/page/PossibleChapter.svelte';
6
+ export { default as Media } from './components/page/Media.svelte';
7
+ export { default as Print } from './components/page/Print.svelte';
8
+ export { default as Glossary } from './components/page/Glossary.svelte';
9
+ export { default as Edition } from './components/page/Edition.svelte';
10
+ export { default as Feedback } from './components/app/Feedback.svelte';
11
+ export { default as Loading } from './components/page/Loading.svelte';
12
+ export { default as EditionModel } from './models/book/Edition';
13
+ export { EDITION } from './components/page/Contexts';
14
+ export { Schema } from './models/book/Schema';
@@ -0,0 +1,27 @@
1
+ import { DocumentReference } from 'firebase/firestore';
2
+ import Edition from './book/Edition';
3
+ import Book from './book/Book';
4
+ import type { Unsubscribe } from 'firebase/auth';
5
+ export declare function listenToPublishedBooks(react: (books: Book[]) => void): Unsubscribe;
6
+ export declare function listenToEditableBooks(userID: string, react: (books: Book[]) => void): Unsubscribe;
7
+ export declare function listenToPartiallyEditableBooks(userID: string, react: (books: Book[]) => void): Unsubscribe;
8
+ export declare function listenToBooksByName(name: string, react: (book: Book[]) => void): Unsubscribe;
9
+ export declare function listenToBookWithID(id: string, react: (book: Book | null) => void): Unsubscribe;
10
+ export declare function listenToEdition(bookID: string, editionID: string, react: (edition: Edition | null) => void): Unsubscribe;
11
+ export declare function listenToChapters(bookID: string, editionID: string, react: (chapters: [DocumentReference, string][]) => void): Unsubscribe;
12
+ /** Hit the authentication database to get user emails. */
13
+ export declare function getUserEmails(uids: string[]): Promise<Map<string, string> | null>;
14
+ export declare function createUser(email: string): Promise<string | null>;
15
+ export declare function createBook(userID: string): Promise<string>;
16
+ export declare function createNewEdition(book: Book): Promise<Book>;
17
+ export declare function updateLock(edition: Edition, uid: string, content: string, lock: boolean): Promise<boolean>;
18
+ /**
19
+ * Persists the edition in the database, creating and deleting chapters as necessary.
20
+ * returns a map of DocumentReferences for new chapters so they can be persisted client side.
21
+ */
22
+ export declare function updateEdition(previousEdition: Edition | undefined, newEdition: Edition): Promise<Map<string, DocumentReference>>;
23
+ export declare function updateBook(book: Book): Promise<void>;
24
+ export declare function isSubdomainAvailable(subdomain: string, book: Book): Promise<boolean>;
25
+ export declare function publish(edition: Edition): Promise<string | {
26
+ url: string;
27
+ }>;
package/models/CRUD.js ADDED
@@ -0,0 +1,262 @@
1
+ import { db, functions } from './Firebase';
2
+ import { collection, getDocs, getDoc, setDoc, doc, addDoc, query, where, deleteDoc, DocumentReference, onSnapshot, QueryFieldFilterConstraint, } from 'firebase/firestore';
3
+ import { httpsCallable } from 'firebase/functions';
4
+ import Edition from './book/Edition';
5
+ import Book, {} from './book/Book';
6
+ function editionPath(bookID, editionID) {
7
+ return `books/${bookID}/editions/${editionID}`;
8
+ }
9
+ const NO_DATABASE_CONNECTION = 'Not connected to database';
10
+ ///////////////
11
+ //// READ BOOKS
12
+ ///////////////
13
+ function listenToBooks(constraint, react) {
14
+ if (!db)
15
+ throw NO_DATABASE_CONNECTION;
16
+ try {
17
+ return onSnapshot(query(collection(db, 'books'), constraint), (snapshot) => react(snapshot.empty
18
+ ? []
19
+ : snapshot.docs.map((doc) => Book.fromJSON(doc.ref, doc.data()))));
20
+ }
21
+ catch (err) {
22
+ throw 'Issue querying database';
23
+ }
24
+ }
25
+ export function listenToPublishedBooks(react) {
26
+ return listenToBooks(where('published', '==', true), react);
27
+ }
28
+ export function listenToEditableBooks(userID, react) {
29
+ return listenToBooks(where('uids', 'array-contains', userID), react);
30
+ }
31
+ export function listenToPartiallyEditableBooks(userID, react) {
32
+ return listenToBooks(where('readuids', 'array-contains', userID), react);
33
+ }
34
+ export function listenToBooksByName(name, react) {
35
+ return listenToBooks(where('domain', '==', name), react);
36
+ }
37
+ export function listenToBookWithID(id, react) {
38
+ if (!db)
39
+ throw NO_DATABASE_CONNECTION;
40
+ const ref = doc(db, 'books', id);
41
+ return onSnapshot(doc(db, 'books', id), (doc) => {
42
+ if (!doc.metadata.hasPendingWrites)
43
+ react(doc.exists()
44
+ ? Book.fromJSON(ref, doc.data())
45
+ : null);
46
+ });
47
+ }
48
+ export function listenToEdition(bookID, editionID, react) {
49
+ if (!db)
50
+ throw NO_DATABASE_CONNECTION;
51
+ return onSnapshot(doc(db, 'books', bookID, 'editions', editionID), (doc) => {
52
+ if (!doc.metadata.hasPendingWrites)
53
+ react(doc.exists()
54
+ ? Edition.fromJSON(doc.ref, doc.data())
55
+ : null);
56
+ });
57
+ }
58
+ export function listenToChapters(bookID, editionID, react) {
59
+ if (!db)
60
+ throw NO_DATABASE_CONNECTION;
61
+ return onSnapshot(collection(db, 'books', bookID, 'editions', editionID, 'chapters'), (docs) => {
62
+ const chapters = [];
63
+ docs.forEach((doc) => {
64
+ chapters.push([doc.ref, doc.data().text]);
65
+ });
66
+ react(chapters);
67
+ });
68
+ }
69
+ /////////////////
70
+ //// MANAGE USERS
71
+ /////////////////
72
+ /** Hit the authentication database to get user emails. */
73
+ export async function getUserEmails(uids) {
74
+ if (!functions)
75
+ throw Error("Can't publish, no connection to Firebase functions.");
76
+ const getUserEmails = httpsCallable(functions, 'getUserEmails');
77
+ const result = await getUserEmails({
78
+ uids,
79
+ });
80
+ return new Map(Object.entries(result.data));
81
+ }
82
+ export async function createUser(email) {
83
+ if (!functions)
84
+ throw Error("Can't publish, no connection to Firebase functions.");
85
+ const createUserWithEmail = httpsCallable(functions, 'createUserWithEmail');
86
+ const result = await createUserWithEmail({
87
+ email,
88
+ });
89
+ return result.data;
90
+ }
91
+ export async function createBook(userID) {
92
+ if (!db)
93
+ throw Error("Can't create book, not connected to Firebase.");
94
+ // Create a new book
95
+ const newBookData = {
96
+ title: 'Untitled',
97
+ authors: [],
98
+ description: '',
99
+ cover: null,
100
+ published: false,
101
+ domain: null,
102
+ editions: [],
103
+ uids: [userID],
104
+ readuids: [],
105
+ };
106
+ // Create the book
107
+ const bookRef = await addDoc(collection(db, 'books'), newBookData);
108
+ // Create a model to store it.
109
+ let book = Book.fromJSON(bookRef, newBookData);
110
+ // Make a new default edition with a single chapter with this user id.
111
+ let newEdition = new Edition(bookRef, undefined, [], 'Untitled', [], 1, '', null, {}, '', [], 'All rights reserved.', '', [], {}, {}, {}, {}, null, {}).withNewChapter();
112
+ // Add the edition to the editions collection in the database so we can get an edition ref.
113
+ const editionRef = await addDoc(collection(db, 'books', bookRef.id, 'editions'), newEdition.toObject());
114
+ // Remember the ref.
115
+ newEdition = newEdition.withRef(editionRef);
116
+ // Now replicate the edition info in the book. We dodge type checking here because we know with certainty
117
+ // that the ref was just added the line before.
118
+ const info = newEdition.getInfo();
119
+ if (info)
120
+ book = book.withEditions([info]);
121
+ // Update the book with the edition info.
122
+ await updateBook(book);
123
+ // Update all of the changes to the edition in Firestore, persisting the refs and chapter text.
124
+ await updateEdition(undefined, newEdition);
125
+ // Return the book id
126
+ return bookRef.id;
127
+ }
128
+ export async function createNewEdition(book) {
129
+ if (!db)
130
+ throw Error("Can't publish draft, no Firebase connection.");
131
+ // Get the latest draft.
132
+ const latestEditionID = book.getLatestEditionID();
133
+ if (latestEditionID === undefined)
134
+ throw 'No editions on this book';
135
+ const latestDraftDoc = await getDoc(doc(db, 'books', book.ref.id, 'editions', latestEditionID));
136
+ const latestDraft = latestDraftDoc.exists()
137
+ ? latestDraftDoc.data()
138
+ : undefined;
139
+ if (latestDraft === undefined)
140
+ return book;
141
+ // Make a copy without chapter and edition refs, because we want to create new ones,
142
+ // and with an incremented edition number.
143
+ const newEdition = latestDraft.withoutRefs();
144
+ // Create a copy of the existing draft as a new edition.
145
+ const newEditionRef = await addDoc(collection(db, 'editions'), newEdition.toObject());
146
+ // Create the edition, creating chapter text as necessary, using the edition sync function.
147
+ updateEdition(undefined, newEdition.withRef(newEditionRef));
148
+ // Put the new edition in the book.
149
+ book = book.withEditions([
150
+ newEdition.getInfo(),
151
+ ...book.getEditions(),
152
+ ]);
153
+ // Update the book.
154
+ updateBook(book);
155
+ return book;
156
+ }
157
+ export async function updateLock(edition, uid, content, lock) {
158
+ if (!db)
159
+ throw NO_DATABASE_CONNECTION;
160
+ if (edition.editionRef === undefined)
161
+ return false;
162
+ if (lock && edition.hasLease(uid, content))
163
+ return true;
164
+ if (!lock && !edition.hasLease(uid, content))
165
+ return true;
166
+ await setDoc(doc(db, editionPath(edition.bookRef.id, edition.editionRef.id)), edition.withLock(uid, content, lock).toObject());
167
+ return lock;
168
+ }
169
+ /**
170
+ * Persists the edition in the database, creating and deleting chapters as necessary.
171
+ * returns a map of DocumentReferences for new chapters so they can be persisted client side.
172
+ */
173
+ export async function updateEdition(previousEdition, newEdition) {
174
+ if (!db)
175
+ throw Error("Can't update edition, not connected to Firebase.");
176
+ // Get the reference to the edition, fail if we don't have one.
177
+ const editionRef = newEdition.getEditionRef();
178
+ if (!editionRef)
179
+ throw Error('Book given has no ID');
180
+ const newChapterRefs = new Map();
181
+ // Create any new chapters that aren't in the current edition, and update text if it changed.
182
+ for (const newChapter of newEdition.chapters) {
183
+ if (newChapter.ref === undefined) {
184
+ // Make the new chapter's text.
185
+ const newChapterRef = await addDoc(collection(db, editionPath(newEdition.bookRef.id, editionRef.id), 'chapters'), { text: newChapter.text });
186
+ // Add the ref of the new chapter to the revised chapter.
187
+ newEdition = newEdition.withRevisedChapter(newChapter, newChapter.withRef(newChapterRef));
188
+ // Map the chapter ref to it's id.
189
+ newChapterRefs.set(newChapter.id, newChapterRef);
190
+ }
191
+ // If we have a previous version, did the text change? If so, update it.
192
+ else {
193
+ const previousChapter = previousEdition === undefined
194
+ ? undefined
195
+ : previousEdition.getChapterByRef(newChapter.ref);
196
+ if (previousChapter === undefined ||
197
+ newChapter.text !== previousChapter.text) {
198
+ await setDoc(doc(db, editionPath(newEdition.bookRef.id, editionRef.id), 'chapters', newChapter.ref.id), { text: newChapter.text });
199
+ }
200
+ }
201
+ }
202
+ // Remove any chapters from Firebase that are removed.
203
+ if (previousEdition) {
204
+ for (const previousChapter of previousEdition.chapters) {
205
+ if (previousChapter.ref &&
206
+ newEdition.getChapterByRef(previousChapter.ref) === undefined) {
207
+ await deleteDoc(previousChapter.ref);
208
+ }
209
+ }
210
+ }
211
+ // If the edition's summary info changed, update it.
212
+ if (previousEdition !== undefined) {
213
+ const previousInfo = previousEdition.getInfo();
214
+ const newInfo = newEdition.getInfo();
215
+ if (previousInfo && newInfo) {
216
+ const previousKeys = Object.keys(previousInfo);
217
+ const newKeys = Object.keys(newInfo);
218
+ if (previousKeys.length !== newKeys.length ||
219
+ !previousKeys.every((key) => previousInfo[key] === newInfo[key])) {
220
+ const bookDoc = await getDoc(doc(db, 'books', newEdition.bookRef.id));
221
+ if (!bookDoc.exists())
222
+ throw Error('Book does not exist');
223
+ const book = Book.fromJSON(newEdition.bookRef, bookDoc.data());
224
+ updateBook(book.withRevisedEdition(previousEdition, newEdition));
225
+ }
226
+ }
227
+ }
228
+ // Finally, update the edition's document.
229
+ await setDoc(doc(db, editionPath(newEdition.bookRef.id, editionRef.id)), newEdition.toObject());
230
+ return newChapterRefs;
231
+ }
232
+ export async function updateBook(book) {
233
+ if (!db)
234
+ throw Error("Can't update book, not connected to Firebase.");
235
+ await setDoc(doc(db, 'books', book.getRefID()), book.toJSON());
236
+ }
237
+ export async function isSubdomainAvailable(subdomain, book) {
238
+ if (!db)
239
+ throw Error('Not connected to Firebase.');
240
+ const matches = await getDocs(query(collection(db, 'books'), where('domain', '==', subdomain)));
241
+ return matches.empty || matches.docs[0].id === book.getRefID();
242
+ }
243
+ export async function publish(edition) {
244
+ if (!db)
245
+ throw Error('Cannot publish, no database connection');
246
+ if (!functions)
247
+ throw Error('Cannot publish, no cloud connection');
248
+ const editionRef = edition.getEditionRef();
249
+ const bookRef = edition.getBookRef();
250
+ if (editionRef === undefined)
251
+ return `Cannot publish, no edition ID`;
252
+ // Get a reference to the publishing function
253
+ const publishEdition = httpsCallable(functions, 'publishEdition');
254
+ // Call the function, passing
255
+ const result = await publishEdition({
256
+ bookID: bookRef.id,
257
+ editionID: editionRef.id,
258
+ });
259
+ return result.data;
260
+ // Update the edition's published status in the book.
261
+ // await updateBook(book.withEditionAsPublished(true, index));
262
+ }
@@ -2,3 +2,4 @@ export declare const app: import("@firebase/app").FirebaseApp | undefined;
2
2
  export declare const auth: import("@firebase/auth").Auth | undefined;
3
3
  export declare const db: import("@firebase/firestore").Firestore | undefined;
4
4
  export declare const storage: import("@firebase/storage").FirebaseStorage | undefined;
5
+ export declare const functions: import("@firebase/functions").Functions | undefined;