bookish-press 0.7.4 → 0.9.2

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 (276) hide show
  1. package/README.md +56 -9
  2. package/dist/components/Auth.svelte +29 -39
  3. package/dist/components/Auth.svelte.d.ts +5 -17
  4. package/dist/components/BookPreview.svelte +14 -20
  5. package/dist/components/BookPreview.svelte.d.ts +6 -18
  6. package/dist/components/Link.svelte +19 -30
  7. package/dist/components/Link.svelte.d.ts +7 -20
  8. package/dist/components/app/BookList.svelte +2 -3
  9. package/dist/components/app/BookList.svelte.d.ts +6 -18
  10. package/dist/components/app/Button.svelte +12 -8
  11. package/dist/components/app/Button.svelte.d.ts +10 -23
  12. package/dist/components/app/Feedback.svelte +4 -4
  13. package/dist/components/app/Feedback.svelte.d.ts +6 -19
  14. package/dist/components/app/Head.svelte +2 -2
  15. package/dist/components/app/Head.svelte.d.ts +6 -19
  16. package/dist/components/app/Large.svelte +4 -1
  17. package/dist/components/app/Large.svelte.d.ts +5 -28
  18. package/dist/components/app/Lead.svelte +4 -1
  19. package/dist/components/app/Lead.svelte.d.ts +5 -28
  20. package/dist/components/app/Link.svelte +12 -9
  21. package/dist/components/app/Link.svelte.d.ts +9 -22
  22. package/dist/components/app/Options.svelte +8 -6
  23. package/dist/components/app/Options.svelte.d.ts +8 -20
  24. package/dist/components/app/Paragraph.svelte +2 -2
  25. package/dist/components/app/Paragraph.svelte.d.ts +6 -19
  26. package/dist/components/app/Section.svelte +4 -1
  27. package/dist/components/app/Section.svelte.d.ts +5 -28
  28. package/dist/components/app/Table.svelte +4 -1
  29. package/dist/components/app/Table.svelte.d.ts +5 -28
  30. package/dist/components/app/TextInput.svelte +10 -8
  31. package/dist/components/app/TextInput.svelte.d.ts +12 -23
  32. package/dist/components/chapter/Atom.svelte +4 -7
  33. package/dist/components/chapter/Atom.svelte.d.ts +6 -19
  34. package/dist/components/chapter/Block.svelte +21 -23
  35. package/dist/components/chapter/Block.svelte.d.ts +5 -17
  36. package/dist/components/chapter/Callout.svelte +3 -5
  37. package/dist/components/chapter/Callout.svelte.d.ts +5 -17
  38. package/dist/components/chapter/CaptionedCode.svelte +12 -14
  39. package/dist/components/chapter/CaptionedCode.svelte.d.ts +5 -17
  40. package/dist/components/chapter/ChapterBody.svelte +14 -17
  41. package/dist/components/chapter/ChapterBody.svelte.d.ts +7 -19
  42. package/dist/components/chapter/ChapterBody.test.d.ts +1 -0
  43. package/dist/components/chapter/ChapterBody.test.js +85 -0
  44. package/dist/components/chapter/Citations.svelte +39 -45
  45. package/dist/components/chapter/Citations.svelte.d.ts +5 -17
  46. package/dist/components/chapter/Code.svelte +158 -155
  47. package/dist/components/chapter/Code.svelte.d.ts +10 -23
  48. package/dist/components/chapter/Comment.svelte +30 -23
  49. package/dist/components/chapter/Comment.svelte.d.ts +5 -17
  50. package/dist/components/chapter/Definition.svelte +36 -34
  51. package/dist/components/chapter/Definition.svelte.d.ts +5 -17
  52. package/dist/components/chapter/Embed.svelte +78 -72
  53. package/dist/components/chapter/Embed.svelte.d.ts +8 -20
  54. package/dist/components/chapter/ErrorMessage.svelte +2 -4
  55. package/dist/components/chapter/ErrorMessage.svelte.d.ts +5 -17
  56. package/dist/components/chapter/Figure.svelte +22 -29
  57. package/dist/components/chapter/Figure.svelte.d.ts +9 -22
  58. package/dist/components/chapter/Footnote.svelte +40 -32
  59. package/dist/components/chapter/Footnote.svelte.d.ts +5 -17
  60. package/dist/components/chapter/Format.svelte +26 -41
  61. package/dist/components/chapter/Format.svelte.d.ts +7 -18
  62. package/dist/components/chapter/InlineCode.svelte +7 -8
  63. package/dist/components/chapter/InlineCode.svelte.d.ts +5 -17
  64. package/dist/components/chapter/Label.svelte +5 -11
  65. package/dist/components/chapter/Label.svelte.d.ts +5 -17
  66. package/dist/components/chapter/LineBreak.svelte +1 -3
  67. package/dist/components/chapter/LineBreak.svelte.d.ts +5 -17
  68. package/dist/components/chapter/Link.svelte +17 -23
  69. package/dist/components/chapter/Link.svelte.d.ts +5 -17
  70. package/dist/components/chapter/List.svelte +9 -9
  71. package/dist/components/chapter/List.svelte.d.ts +6 -17
  72. package/dist/components/chapter/Marginal.svelte +59 -60
  73. package/dist/components/chapter/Marginal.svelte.d.ts +10 -22
  74. package/dist/components/chapter/Paragraph.svelte +8 -23
  75. package/dist/components/chapter/Paragraph.svelte.d.ts +6 -18
  76. package/dist/components/chapter/Positioned.svelte +2 -4
  77. package/dist/components/chapter/Positioned.svelte.d.ts +6 -19
  78. package/dist/components/chapter/Problem.svelte +3 -2
  79. package/dist/components/chapter/Problem.svelte.d.ts +5 -28
  80. package/dist/components/chapter/Python.svelte +45 -58
  81. package/dist/components/chapter/Python.svelte.d.ts +6 -18
  82. package/dist/components/chapter/Quote.svelte +5 -7
  83. package/dist/components/chapter/Quote.svelte.d.ts +5 -17
  84. package/dist/components/chapter/Rule.svelte +1 -3
  85. package/dist/components/chapter/Rule.svelte.d.ts +5 -17
  86. package/dist/components/chapter/Table.svelte +6 -8
  87. package/dist/components/chapter/Table.svelte.d.ts +5 -17
  88. package/dist/components/chapter/Text.svelte +54 -69
  89. package/dist/components/chapter/Text.svelte.d.ts +6 -18
  90. package/dist/components/controls/DarkToggle.svelte +7 -8
  91. package/dist/components/controls/DarkToggle.svelte.d.ts +6 -18
  92. package/dist/components/editor/BookishEditor.svelte +583 -761
  93. package/dist/components/editor/BookishEditor.svelte.d.ts +14 -26
  94. package/dist/components/editor/CalloutEditor.svelte +3 -3
  95. package/dist/components/editor/CalloutEditor.svelte.d.ts +5 -17
  96. package/dist/components/editor/CaptionedCodeEditor.svelte +5 -5
  97. package/dist/components/editor/CaptionedCodeEditor.svelte.d.ts +5 -17
  98. package/dist/components/editor/CaretView.svelte +23 -25
  99. package/dist/components/editor/CaretView.svelte.d.ts +15 -27
  100. package/dist/components/editor/CitationsEditor.svelte +25 -28
  101. package/dist/components/editor/CitationsEditor.svelte.d.ts +5 -17
  102. package/dist/components/editor/ConfirmButton.svelte +9 -6
  103. package/dist/components/editor/ConfirmButton.svelte.d.ts +8 -21
  104. package/dist/components/editor/DefinitionEditor.svelte +11 -15
  105. package/dist/components/editor/DefinitionEditor.svelte.d.ts +5 -17
  106. package/dist/components/editor/EmbedEditor.svelte +44 -45
  107. package/dist/components/editor/EmbedEditor.svelte.d.ts +5 -17
  108. package/dist/components/editor/Icon.svelte +1 -1
  109. package/dist/components/editor/Icon.svelte.d.ts +5 -17
  110. package/dist/components/editor/ImageChooser.svelte +15 -18
  111. package/dist/components/editor/ImageChooser.svelte.d.ts +6 -18
  112. package/dist/components/editor/ImageThumbnail.svelte +29 -24
  113. package/dist/components/editor/ImageThumbnail.svelte.d.ts +7 -19
  114. package/dist/components/editor/InlineCodeEditor.svelte +3 -3
  115. package/dist/components/editor/InlineCodeEditor.svelte.d.ts +5 -17
  116. package/dist/components/editor/LabelEditor.svelte +5 -6
  117. package/dist/components/editor/LabelEditor.svelte.d.ts +5 -17
  118. package/dist/components/editor/LanguageEditor.svelte +4 -5
  119. package/dist/components/editor/LanguageEditor.svelte.d.ts +6 -18
  120. package/dist/components/editor/LinkEditor.svelte +52 -68
  121. package/dist/components/editor/LinkEditor.svelte.d.ts +5 -17
  122. package/dist/components/editor/Note.svelte +4 -1
  123. package/dist/components/editor/Note.svelte.d.ts +5 -28
  124. package/dist/components/editor/Permissions.svelte +36 -34
  125. package/dist/components/editor/Permissions.svelte.d.ts +9 -21
  126. package/dist/components/editor/PositionEditor.svelte +6 -7
  127. package/dist/components/editor/PositionEditor.svelte.d.ts +6 -18
  128. package/dist/components/editor/QuoteEditor.svelte +3 -3
  129. package/dist/components/editor/QuoteEditor.svelte.d.ts +5 -17
  130. package/dist/components/editor/Switch.svelte +16 -11
  131. package/dist/components/editor/Switch.svelte.d.ts +9 -21
  132. package/dist/components/editor/TableEditor.svelte +3 -3
  133. package/dist/components/editor/TableEditor.svelte.d.ts +5 -17
  134. package/dist/components/editor/TextEditor.svelte +74 -87
  135. package/dist/components/editor/TextEditor.svelte.d.ts +13 -25
  136. package/dist/components/editor/Toggle.svelte +18 -21
  137. package/dist/components/editor/Toggle.svelte.d.ts +7 -20
  138. package/dist/components/editor/Toolbar.svelte +140 -145
  139. package/dist/components/editor/Toolbar.svelte.d.ts +5 -17
  140. package/dist/components/editor/ToolbarGroup.svelte +4 -4
  141. package/dist/components/editor/ToolbarGroup.svelte.d.ts +6 -19
  142. package/dist/components/editor/ToolbarSpacer.svelte +1 -1
  143. package/dist/components/editor/ToolbarSpacer.svelte.d.ts +22 -21
  144. package/dist/components/editor/URLEditor.svelte +3 -5
  145. package/dist/components/editor/URLEditor.svelte.d.ts +7 -19
  146. package/dist/components/page/Acknowledgements.svelte +14 -8
  147. package/dist/components/page/Acknowledgements.svelte.d.ts +3 -16
  148. package/dist/components/page/Analytics.svelte +2 -3
  149. package/dist/components/page/Analytics.svelte.d.ts +6 -17
  150. package/dist/components/page/Authors.svelte +29 -29
  151. package/dist/components/page/Authors.svelte.d.ts +11 -23
  152. package/dist/components/page/BookLoader.svelte +47 -43
  153. package/dist/components/page/BookLoader.svelte.d.ts +5 -17
  154. package/dist/components/page/BulkReferenceEditor.svelte +43 -26
  155. package/dist/components/page/BulkReferenceEditor.svelte.d.ts +3 -16
  156. package/dist/components/page/Chapter.svelte +224 -249
  157. package/dist/components/page/Chapter.svelte.d.ts +6 -18
  158. package/dist/components/page/ChapterContext.d.ts +3 -1
  159. package/dist/components/page/ChapterNumber.svelte +4 -1
  160. package/dist/components/page/ChapterNumber.svelte.d.ts +5 -28
  161. package/dist/components/page/ChapterTitle.svelte +4 -4
  162. package/dist/components/page/ChapterTitle.svelte.d.ts +6 -19
  163. package/dist/components/page/Contexts.js +2 -2
  164. package/dist/components/page/DefinitionView.svelte +51 -44
  165. package/dist/components/page/DefinitionView.svelte.d.ts +6 -18
  166. package/dist/components/page/Description.svelte +10 -4
  167. package/dist/components/page/Description.svelte.d.ts +16 -14
  168. package/dist/components/page/DownloadEPUB.svelte +234 -0
  169. package/dist/components/page/DownloadEPUB.svelte.d.ts +3 -0
  170. package/dist/components/page/EditableHeader.svelte +4 -6
  171. package/dist/components/page/EditableHeader.svelte.d.ts +7 -18
  172. package/dist/components/page/Edition.svelte +57 -71
  173. package/dist/components/page/Edition.svelte.d.ts +7 -20
  174. package/dist/components/page/EditionLoader.svelte +119 -82
  175. package/dist/components/page/EditionLoader.svelte.d.ts +6 -19
  176. package/dist/components/page/Editions.svelte +26 -31
  177. package/dist/components/page/Editions.svelte.d.ts +5 -17
  178. package/dist/components/page/Glossary.svelte +31 -35
  179. package/dist/components/page/Glossary.svelte.d.ts +3 -16
  180. package/dist/components/page/Header.svelte +43 -49
  181. package/dist/components/page/Header.svelte.d.ts +19 -30
  182. package/dist/components/page/Index.svelte +46 -46
  183. package/dist/components/page/Index.svelte.d.ts +3 -16
  184. package/dist/components/page/Instructions.svelte +2 -2
  185. package/dist/components/page/Instructions.svelte.d.ts +6 -19
  186. package/dist/components/page/License.svelte +13 -7
  187. package/dist/components/page/License.svelte.d.ts +16 -14
  188. package/dist/components/page/Loading.svelte +9 -9
  189. package/dist/components/page/Loading.svelte.d.ts +22 -21
  190. package/dist/components/page/Media.svelte +36 -27
  191. package/dist/components/page/Media.svelte.d.ts +3 -16
  192. package/dist/components/page/MediaPreview.svelte +22 -19
  193. package/dist/components/page/MediaPreview.svelte.d.ts +8 -21
  194. package/dist/components/page/Muted.svelte +4 -1
  195. package/dist/components/page/Muted.svelte.d.ts +5 -28
  196. package/dist/components/page/Outline.svelte +75 -97
  197. package/dist/components/page/Outline.svelte.d.ts +8 -20
  198. package/dist/components/page/Page.svelte +23 -33
  199. package/dist/components/page/Page.svelte.d.ts +7 -20
  200. package/dist/components/page/PageHeader.svelte +2 -2
  201. package/dist/components/page/PageHeader.svelte.d.ts +6 -19
  202. package/dist/components/page/PageParagraph.svelte +4 -1
  203. package/dist/components/page/PageParagraph.svelte.d.ts +5 -28
  204. package/dist/components/page/PossibleChapter.svelte +7 -7
  205. package/dist/components/page/PossibleChapter.svelte.d.ts +3 -16
  206. package/dist/components/page/PossibleReference.svelte +4 -5
  207. package/dist/components/page/PossibleReference.svelte.d.ts +6 -18
  208. package/dist/components/page/Print.svelte +11 -12
  209. package/dist/components/page/Print.svelte.d.ts +3 -16
  210. package/dist/components/page/Publish.svelte +47 -47
  211. package/dist/components/page/Publish.svelte.d.ts +3 -16
  212. package/dist/components/page/Reference.svelte +24 -35
  213. package/dist/components/page/Reference.svelte.d.ts +6 -18
  214. package/dist/components/page/References.svelte +21 -22
  215. package/dist/components/page/References.svelte.d.ts +3 -16
  216. package/dist/components/page/Rows.svelte +5 -2
  217. package/dist/components/page/Rows.svelte.d.ts +5 -28
  218. package/dist/components/page/Search.svelte +59 -61
  219. package/dist/components/page/Search.svelte.d.ts +3 -16
  220. package/dist/components/page/Status.svelte +2 -2
  221. package/dist/components/page/Status.svelte.d.ts +16 -14
  222. package/dist/components/page/SubdomainEditor.svelte +11 -11
  223. package/dist/components/page/SubdomainEditor.svelte.d.ts +16 -14
  224. package/dist/components/page/TableOfContents.svelte +157 -124
  225. package/dist/components/page/TableOfContents.svelte.d.ts +3 -16
  226. package/dist/components/page/TableOfContentsImage.svelte +6 -7
  227. package/dist/components/page/TableOfContentsImage.svelte.d.ts +6 -18
  228. package/dist/components/page/TableOfContentsRow.svelte +32 -32
  229. package/dist/components/page/TableOfContentsRow.svelte.d.ts +10 -22
  230. package/dist/components/page/ThemeEditor.svelte +35 -28
  231. package/dist/components/page/ThemeEditor.svelte.d.ts +3 -16
  232. package/dist/components/page/ThemeEditorPreview.svelte +11 -13
  233. package/dist/components/page/ThemeEditorPreview.svelte.d.ts +5 -17
  234. package/dist/components/page/ThemeSetEditor.svelte +4 -6
  235. package/dist/components/page/ThemeSetEditor.svelte.d.ts +7 -19
  236. package/dist/components/page/ThemeVariableEditor.svelte +9 -11
  237. package/dist/components/page/ThemeVariableEditor.svelte.d.ts +7 -19
  238. package/dist/components/page/Title.svelte +4 -1
  239. package/dist/components/page/Title.svelte.d.ts +5 -28
  240. package/dist/components/page/Unknown.svelte +11 -8
  241. package/dist/components/page/Unknown.svelte.d.ts +5 -17
  242. package/dist/epub/build.d.ts +39 -0
  243. package/dist/epub/build.js +143 -0
  244. package/dist/epub/build.test.d.ts +1 -0
  245. package/dist/epub/build.test.js +411 -0
  246. package/dist/epub/images.d.ts +79 -0
  247. package/dist/epub/images.js +260 -0
  248. package/dist/epub/images.test.d.ts +1 -0
  249. package/dist/epub/images.test.js +129 -0
  250. package/dist/epub/package.d.ts +75 -0
  251. package/dist/epub/package.js +392 -0
  252. package/dist/epub/stylesheet.test.d.ts +1 -0
  253. package/dist/epub/stylesheet.test.js +243 -0
  254. package/dist/epub/xhtml.d.ts +69 -0
  255. package/dist/epub/xhtml.js +367 -0
  256. package/dist/epub/xhtml.test.d.ts +1 -0
  257. package/dist/epub/xhtml.test.js +283 -0
  258. package/dist/epub/zip.d.ts +35 -0
  259. package/dist/epub/zip.js +202 -0
  260. package/dist/epub/zip.test.d.ts +1 -0
  261. package/dist/epub/zip.test.js +171 -0
  262. package/dist/index.d.ts +1 -0
  263. package/dist/index.js +1 -0
  264. package/dist/models/Firebase.js +18 -4
  265. package/dist/models/book/Book.js +2 -1
  266. package/dist/models/book/BookMedia.js +1 -2
  267. package/dist/models/book/Chapter.js +3 -2
  268. package/dist/models/book/ChapterID.d.ts +1 -1
  269. package/dist/models/book/Edition.d.ts +1 -1
  270. package/dist/models/book/Edition.js +6 -1
  271. package/dist/models/chapter/BlocksNode.js +3 -1
  272. package/dist/models/chapter/BlocksNode.test.js +5 -1
  273. package/dist/models/chapter/Node.test.js +2 -2
  274. package/dist/models/chapter/TextNode.js +8 -5
  275. package/dist/models/chapter/TextNode.test.js +8 -0
  276. package/package.json +36 -22
@@ -1,83 +1,69 @@
1
- <script>import smoothscroll from 'smoothscroll-polyfill';
2
- import { goto } from '$app/navigation';
3
- import { onMount, setContext } from 'svelte';
4
- import { writable } from 'svelte/store';
5
- import { BASE, DARK_MODE, getBook, } from './Contexts';
6
- import { BookishTheme } from '../../models/book/Theme';
7
- import { isDark, setDark } from '../../util/dark';
8
- import { page } from '$app/stores';
9
- import Title from './Title.svelte';
10
- import Page from './Page.svelte';
11
- // Poly fill smooth scrolling for Safari.
1
+ <script lang="ts">import smoothscroll from "smoothscroll-polyfill";
2
+ import { goto } from "$app/navigation";
3
+ import { onMount, setContext, untrack } from "svelte";
4
+ import { writable } from "svelte/store";
5
+ import {
6
+ BASE,
7
+ DARK_MODE,
8
+ getBook
9
+ } from "./Contexts";
10
+ import { BookishTheme } from "../../models/book/Theme";
11
+ import { isDark, setDark } from "../../util/dark";
12
+ import { page } from "$app/state";
13
+ import Title from "./Title.svelte";
14
+ import Page from "./Page.svelte";
15
+ import Parser from "../../models/chapter/Parser";
16
+ import EmbedNode from "../../models/chapter/EmbedNode";
12
17
  onMount(() => smoothscroll.polyfill());
13
- // The book and edition to render
14
- export let edition;
15
- // The base path allows links to adjust to different routing contexts in which a book is placed.
16
- // For example, when the book is hosted alone, all routes might start with the bare root "/",
17
- // but when the book is being viewed or edited in the Bookish app, it needs a prefix for the
18
- // route in the app.
19
- export let base = '';
18
+ let { edition, base = "", children } = $props();
19
+ let coverURL = $derived.by(() => {
20
+ const cover = edition?.getImage("cover");
21
+ if (!cover) return void 0;
22
+ const node = Parser.parseEmbed(edition, cover);
23
+ const url = node instanceof EmbedNode ? node.getURL() : void 0;
24
+ if (!url || url.length === 0) return void 0;
25
+ return url.startsWith("http") ? url : `${base}/images/${url}`;
26
+ });
20
27
  let book = getBook();
21
- // When the base changes, update the context.
22
- let baseStore = writable(base);
23
- $: setContext(BASE, baseStore);
24
- $: baseStore.set(base);
25
- // Default dark mode to whatever's stored in local storage, if anything.
26
- // respect user choice on the website despite the system theme
28
+ let baseStore = writable(untrack(() => base));
29
+ setContext(BASE, baseStore);
30
+ $effect.pre(() => {
31
+ baseStore.set(base);
32
+ });
27
33
  let darkMode = writable(isDark());
28
- // Expose dark mode to descendants
29
34
  setContext(DARK_MODE, darkMode);
30
- // When dark mode changes, update the body's class list.
31
- $: {
32
- setDark($darkMode);
33
- // Set the theme, whatever it is, and change it when the edition changes
34
- setTheme(edition?.getTheme() ?? BookishTheme);
35
- }
36
- // The CSS to set on the edition.
37
- let themeCSS;
38
- // Set the theme on mount.
39
- onMount(() => {
40
- setTheme(edition?.getTheme() ?? BookishTheme);
35
+ let themeCSS = $derived(
36
+ themeToCSS(edition?.getTheme() ?? BookishTheme)
37
+ );
38
+ $effect.pre(() => {
39
+ setDark($darkMode);
41
40
  });
42
- // Redirect old hash routes by simply replacing their hash before routing.
43
- if (typeof window !== 'undefined' && window.location.hash.startsWith('#/'))
44
- goto(location.hash.replace('#', ''));
45
- /** Given a theme, sets the appropriate CSS rules in the browser to apply the theme. */
46
- function setTheme(theme) {
47
- if (theme === null)
48
- theme = BookishTheme;
49
- themeCSS = `
50
- ${(theme.imports ?? [])
51
- .map((url) => `@import url(${url});`)
52
- .join('\n')}
41
+ if (typeof window !== "undefined" && window.location.hash.startsWith("#/"))
42
+ goto(location.hash.replace("#", ""));
43
+ function themeToCSS(theme) {
44
+ if (theme === null) theme = BookishTheme;
45
+ return `
46
+ ${(theme.imports ?? []).map((url) => `@import url(${url});`).join("\n")}
53
47
  .bookish {
54
- ${theme.light ? toRules(theme.light) : ''}
55
- ${theme.fonts ? toRules(theme.fonts) : ''}
56
- ${theme.sizes ? toRules(theme.sizes) : ''}
57
- ${theme.weights ? toRules(theme.weights) : ''}
58
- ${theme.spacing ? toRules(theme.spacing) : ''}
48
+ ${theme.light ? toRules(theme.light) : ""}
49
+ ${theme.fonts ? toRules(theme.fonts) : ""}
50
+ ${theme.sizes ? toRules(theme.sizes) : ""}
51
+ ${theme.weights ? toRules(theme.weights) : ""}
52
+ ${theme.spacing ? toRules(theme.spacing) : ""}
59
53
  }
60
54
  .dark {
61
- ${theme.dark ? toRules(theme.dark) : ''}
55
+ ${theme.dark ? toRules(theme.dark) : ""}
62
56
  }
63
57
  `;
64
58
  }
65
59
  function toRules(set) {
66
- return Object.keys(set)
67
- .map((name) => {
68
- const value = set[name];
69
- if (value.length > 0) {
70
- const cssVariable = '--bookish-' +
71
- name
72
- .replace(/([a-z])([A-Z])/g, '$1 $2')
73
- .split(' ')
74
- .map((s) => s.toLowerCase())
75
- .join('-')
76
- .replace(/([0-9])/g, '-$1-');
77
- return `${cssVariable}: ${value};`;
78
- }
79
- })
80
- .join('\n\t\t');
60
+ return Object.keys(set).map((name) => {
61
+ const value = set[name];
62
+ if (value.length > 0) {
63
+ const cssVariable = "--bookish-" + name.replace(/([a-z])([A-Z])/g, "$1 $2").split(" ").map((s) => s.toLowerCase()).join("-").replace(/([0-9])/g, "-$1-");
64
+ return `${cssVariable}: ${value};`;
65
+ }
66
+ }).join("\n ");
81
67
  }
82
68
  </script>
83
69
 
@@ -87,7 +73,7 @@ function toRules(set) {
87
73
 
88
74
  {#if edition}
89
75
  <meta property="og:title" content={edition.getTitle()} />
90
- <meta property="og:image" content={edition.getImage('cover')} />
76
+ {#if coverURL}<meta property="og:image" content={coverURL} />{/if}
91
77
  <meta property="og:description" content={edition.getDescription()} />
92
78
  <meta property="og:type" content="book" />
93
79
  <meta property="og:author" content={edition.getAuthorsText()} />
@@ -95,7 +81,7 @@ function toRules(set) {
95
81
  property="og:url"
96
82
  content={edition.base ??
97
83
  `https://bookish.press/${
98
- $book && $book.domain ? $book.domain : $page.params.bookid
84
+ $book && $book.domain ? $book.domain : page.params.bookid
99
85
  }`}
100
86
  />
101
87
  {/if}
@@ -103,7 +89,7 @@ function toRules(set) {
103
89
 
104
90
  <main class="bookish {$darkMode ? ' dark' : ''}">
105
91
  {#if edition}
106
- <slot />
92
+ {@render children?.()}
107
93
  <!-- No edition to render? Coming soon. -->
108
94
  {:else if $book}
109
95
  <Page title={$book.title}>
@@ -1,22 +1,9 @@
1
- import { SvelteComponent } from "svelte";
2
1
  import type EditionModel from '../../models/book/Edition';
3
- declare const __propDef: {
4
- props: {
5
- edition: EditionModel | undefined;
6
- base?: string;
7
- };
8
- events: {
9
- [evt: string]: CustomEvent<any>;
10
- };
11
- slots: {
12
- default: {};
13
- };
14
- exports?: {} | undefined;
15
- bindings?: string | undefined;
16
- };
17
- export type EditionProps = typeof __propDef.props;
18
- export type EditionEvents = typeof __propDef.events;
19
- export type EditionSlots = typeof __propDef.slots;
20
- export default class Edition extends SvelteComponent<EditionProps, EditionEvents, EditionSlots> {
2
+ interface Props {
3
+ edition: EditionModel | undefined;
4
+ base?: string;
5
+ children?: import('svelte').Snippet;
21
6
  }
22
- export {};
7
+ declare const Edition: import("svelte").Component<Props, {}, "">;
8
+ type Edition = ReturnType<typeof Edition>;
9
+ export default Edition;
@@ -1,98 +1,135 @@
1
- <script>import Loading from './Loading.svelte';
2
- import Edition from './Edition.svelte';
3
- import Feedback from '../app/Feedback.svelte';
4
- import { getBook, getEdition, getUser, getChapterText, } from './Contexts';
5
- import { onDestroy } from 'svelte';
6
- import { page } from '$app/stores';
7
- import { listenToChapters, listenToEdition } from '../../models/CRUD';
8
- export let write;
9
- let currentEditionID;
1
+ <script lang="ts">import Loading from "./Loading.svelte";
2
+ import Edition from "./Edition.svelte";
3
+ import Feedback from "../app/Feedback.svelte";
4
+ import {
5
+ getBook,
6
+ getEdition,
7
+ getStatus,
8
+ getUser,
9
+ getChapterText
10
+ } from "./Contexts";
11
+ import BookSaveStatus from "../../models/book/BookSaveStatus";
12
+ import { get } from "svelte/store";
13
+ import { onDestroy, untrack } from "svelte";
14
+ import { page } from "$app/state";
15
+ import { listenToChapters, listenToEdition } from "../../models/CRUD";
16
+ let { write, children } = $props();
17
+ let currentEditionID = $state();
10
18
  let auth = getUser();
11
19
  let book = getBook();
12
20
  let edition = getEdition();
13
- /** Mapping from Firestore docuemnt IDs to chapter text */
14
- let chapterText = new Map();
15
- let editionUnsub = undefined;
16
- let chaptersUnsub = undefined;
17
- let error = undefined;
21
+ let status = getStatus();
22
+ let locallyEdited = false;
23
+ let applyingSnapshot = false;
24
+ const localEditWatch = edition.subscribe(() => {
25
+ if (!applyingSnapshot) locallyEdited = true;
26
+ });
27
+ const statusWatch = status?.subscribe((current) => {
28
+ if (current === BookSaveStatus.Saved) locallyEdited = false;
29
+ });
30
+ function skipStaleSnapshot() {
31
+ const current = status ? get(status) : void 0;
32
+ return locallyEdited && (current === BookSaveStatus.Changed || current === BookSaveStatus.Saving);
33
+ }
34
+ function applySnapshot(apply) {
35
+ applyingSnapshot = true;
36
+ try {
37
+ apply();
38
+ } finally {
39
+ applyingSnapshot = false;
40
+ }
41
+ }
42
+ let chapterText = /* @__PURE__ */ new Map();
43
+ let editionUnsub = void 0;
44
+ let chaptersUnsub = void 0;
45
+ let error = $state(void 0);
18
46
  function unsub() {
19
- // Unsubscribe to the old edition document if we were listening to one.
20
- if (editionUnsub)
21
- editionUnsub();
22
- if (chaptersUnsub)
23
- chaptersUnsub();
47
+ if (editionUnsub) editionUnsub();
48
+ if (chaptersUnsub) chaptersUnsub();
24
49
  }
25
50
  function listen() {
26
- unsub();
27
- error = undefined;
28
- // If we no longer have a book, we can't get an edition.
29
- if ($book === undefined) {
30
- edition.set(undefined);
31
- error = 'Unknown book.';
32
- return;
51
+ unsub();
52
+ error = void 0;
53
+ if ($book === void 0) {
54
+ edition.set(void 0);
55
+ error = "Unknown book.";
56
+ return;
57
+ } else {
58
+ currentEditionID = page.params.editionid;
59
+ const latestPublished = !write;
60
+ let editionID;
61
+ if (currentEditionID === void 0) {
62
+ if (latestPublished) {
63
+ editionID = $book.getLatestPublishedEditionID();
64
+ if (editionID === void 0)
65
+ error = "There is no published edition of this book.";
66
+ } else {
67
+ editionID = $book.getLatestEditionID();
68
+ }
69
+ } else {
70
+ editionID = $book.getEditionNumberID(
71
+ parseFloat(currentEditionID)
72
+ );
73
+ if (editionID === void 0)
74
+ error = `There is no ${currentEditionID} edition of this book`;
33
75
  }
34
- else {
35
- currentEditionID = $page.params.editionid;
36
- const latestPublished = !write;
37
- // Figure out which edition to load.
38
- let editionID;
39
- if (currentEditionID === undefined) {
40
- if (latestPublished) {
41
- editionID = $book.getLatestPublishedEditionID();
42
- if (editionID === undefined)
43
- error = 'There is no published edition of this book.';
44
- }
45
- else {
46
- editionID = $book.getLatestEditionID();
47
- }
76
+ if (editionID !== void 0) {
77
+ editionUnsub = listenToEdition(
78
+ $book.getID(),
79
+ editionID,
80
+ (ed) => {
81
+ if (skipStaleSnapshot()) return;
82
+ if (ed) {
83
+ applySnapshot(
84
+ () => edition.set(ed.withChapterText(chapterText))
85
+ );
86
+ } else {
87
+ applySnapshot(() => edition.set(void 0));
88
+ error = "Unable to load edition";
89
+ }
48
90
  }
49
- else {
50
- editionID = $book.getEditionNumberID(parseFloat(currentEditionID));
51
- if (editionID === undefined)
52
- error = `There is no ${currentEditionID} edition of this book`;
53
- }
54
- // Listen to the doc for changes and listen to all of its chapters.
55
- if (editionID !== undefined) {
56
- editionUnsub = listenToEdition($book.getID(), editionID, (ed) => {
57
- if (ed) {
58
- // Before setting the new edition, augmented it with the chapter text.
59
- edition.set(ed.withChapterText(chapterText));
60
- }
61
- else {
62
- edition.set(undefined);
63
- error = 'Unable to load edition';
64
- }
65
- });
66
- chaptersUnsub = listenToChapters($book.getID(), editionID, (chapters) => {
67
- // Update the text of the chapters we received.
68
- for (const [ref, text] of chapters)
69
- chapterText.set(ref.id, text);
70
- // Update the chapter text in the current edition.
71
- if ($edition) {
72
- edition.set($edition.withChapterText(chapterText));
73
- }
74
- });
91
+ );
92
+ chaptersUnsub = listenToChapters(
93
+ $book.getID(),
94
+ editionID,
95
+ (chapters) => {
96
+ const stale = skipStaleSnapshot();
97
+ for (const [ref, text] of chapters)
98
+ if (!stale || !chapterText.has(ref.id))
99
+ chapterText.set(ref.id, text);
100
+ if ($edition) {
101
+ applySnapshot(
102
+ () => edition.set(
103
+ $edition.withChapterText(chapterText)
104
+ )
105
+ );
106
+ }
75
107
  }
108
+ );
76
109
  }
110
+ }
77
111
  }
78
- // Remember the chapter text whenever the edition changes, so we don't overwrite stale text.
79
- // when other things change.
80
- $: if ($edition) {
112
+ $effect.pre(() => {
113
+ if ($edition) {
81
114
  for (const chapter of $edition.chapters) {
82
- if (chapter.ref && chapter.text !== null)
83
- chapterText.set(chapter.ref.id, chapter.text);
115
+ if (chapter.ref && chapter.text !== null)
116
+ chapterText.set(chapter.ref.id, chapter.text);
84
117
  }
85
- }
86
- // Whenever the book changes, change the listener.
87
- $: if ((currentEditionID === undefined ||
88
- $page.params.editionid !== currentEditionID) &&
89
- $auth &&
90
- $auth.user !== null)
91
- listen();
92
- // When unmounted, unset the stores — no longer viewing a book.
118
+ }
119
+ });
120
+ $effect(() => {
121
+ const requestedEditionID = page.params.editionid;
122
+ const user = $auth?.user;
123
+ untrack(() => {
124
+ if ((currentEditionID === void 0 || requestedEditionID !== currentEditionID) && user !== null && user !== void 0)
125
+ listen();
126
+ });
127
+ });
93
128
  onDestroy(() => {
94
- edition.set(undefined);
95
- unsub();
129
+ localEditWatch();
130
+ statusWatch?.();
131
+ edition.set(void 0);
132
+ unsub();
96
133
  });
97
134
  </script>
98
135
 
@@ -107,6 +144,6 @@ onDestroy(() => {
107
144
  ? `/write/${$book.getID()}/${$edition.getEditionNumber()}`
108
145
  : `/${$book.getSubdomain() ?? $book.getID()}`}
109
146
  >
110
- <slot />
147
+ {@render children?.()}
111
148
  </Edition>
112
149
  {/if}
@@ -1,20 +1,7 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- write: boolean;
5
- };
6
- events: {
7
- [evt: string]: CustomEvent<any>;
8
- };
9
- slots: {
10
- default: {};
11
- };
12
- exports?: {} | undefined;
13
- bindings?: string | undefined;
14
- };
15
- export type EditionLoaderProps = typeof __propDef.props;
16
- export type EditionLoaderEvents = typeof __propDef.events;
17
- export type EditionLoaderSlots = typeof __propDef.slots;
18
- export default class EditionLoader extends SvelteComponent<EditionLoaderProps, EditionLoaderEvents, EditionLoaderSlots> {
1
+ interface Props {
2
+ write: boolean;
3
+ children?: import('svelte').Snippet;
19
4
  }
20
- export {};
5
+ declare const EditionLoader: import("svelte").Component<Props, {}, "">;
6
+ type EditionLoader = ReturnType<typeof EditionLoader>;
7
+ export default EditionLoader;
@@ -1,41 +1,36 @@
1
- <script>import { createNewEdition } from '../../models/CRUD';
2
- import Instructions from './Instructions.svelte';
3
- import Note from '../editor/Note.svelte';
4
- import { getBook, getUser, isBookEditable } from './Contexts';
5
- import Button from '../app/Button.svelte';
6
- import Link from '../app/Link.svelte';
7
- import Format from '../chapter/Format.svelte';
8
- import Parser from '../../models/chapter/Parser';
9
- import Permissions from '../editor/Permissions.svelte';
10
- export let editors = true;
1
+ <script lang="ts">import { createNewEdition } from "../../models/CRUD";
2
+ import Instructions from "./Instructions.svelte";
3
+ import Note from "../editor/Note.svelte";
4
+ import { getBook, getUser, isBookEditable } from "./Contexts";
5
+ import Button from "../app/Button.svelte";
6
+ import Link from "../app/Link.svelte";
7
+ import Format from "../chapter/Format.svelte";
8
+ import Parser from "../../models/chapter/Parser";
9
+ import Permissions from "../editor/Permissions.svelte";
10
+ let { editors = true } = $props();
11
11
  let book = getBook();
12
12
  let editable = isBookEditable();
13
13
  let user = getUser();
14
- $: editions = $book?.getEditions();
15
- $: latestPublishedID = $book?.getLatestPublishedEditionID();
16
- let publisher = false;
17
- $: {
18
- if ($user && $user.user)
19
- updateUserClaims();
20
- }
14
+ let publisher = $state(false);
21
15
  async function updateUserClaims() {
22
- if ($user === undefined || $user.user === null)
23
- return;
24
- const token = await $user.user.getIdTokenResult();
25
- publisher =
26
- 'publisher' in token.claims && token.claims.publisher === true;
16
+ if ($user === void 0 || $user.user === null) return;
17
+ const token = await $user.user.getIdTokenResult();
18
+ publisher = "publisher" in token.claims && token.claims.publisher === true;
27
19
  }
28
20
  async function createEdition() {
29
- if ($book === undefined)
30
- return;
31
- try {
32
- const revisedBook = await createNewEdition($book);
33
- book.set(revisedBook);
34
- }
35
- catch (err) {
36
- console.error('Error creating new edition:', err);
37
- }
21
+ if ($book === void 0) return;
22
+ try {
23
+ const revisedBook = await createNewEdition($book);
24
+ book.set(revisedBook);
25
+ } catch (err) {
26
+ console.error("Error creating new edition:", err);
27
+ }
38
28
  }
29
+ let editions = $derived($book?.getEditions());
30
+ let latestPublishedID = $derived($book?.getLatestPublishedEditionID());
31
+ $effect(() => {
32
+ if ($user && $user.user) updateUserClaims();
33
+ });
39
34
  </script>
40
35
 
41
36
  {#if $book && editions}
@@ -1,18 +1,6 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- editors?: boolean;
5
- };
6
- events: {
7
- [evt: string]: CustomEvent<any>;
8
- };
9
- slots: {};
10
- exports?: {} | undefined;
11
- bindings?: string | undefined;
12
- };
13
- export type EditionsProps = typeof __propDef.props;
14
- export type EditionsEvents = typeof __propDef.events;
15
- export type EditionsSlots = typeof __propDef.slots;
16
- export default class Editions extends SvelteComponent<EditionsProps, EditionsEvents, EditionsSlots> {
1
+ interface Props {
2
+ editors?: boolean;
17
3
  }
18
- export {};
4
+ declare const Editions: import("svelte").Component<Props, {}, "">;
5
+ type Editions = ReturnType<typeof Editions>;
6
+ export default Editions;
@@ -1,31 +1,25 @@
1
- <script>import Header from './Header.svelte';
2
- import Outline from './Outline.svelte';
3
- import Page from './Page.svelte';
4
- import ChapterIDs from '../../models/book/ChapterID';
5
- import DefinitionView from './DefinitionView.svelte';
6
- import { getUser, getEdition, isEditionEditable } from './Contexts';
7
- import Instructions from './Instructions.svelte';
8
- import Button from '../app/Button.svelte';
1
+ <script lang="ts">import Header from "./Header.svelte";
2
+ import Outline from "./Outline.svelte";
3
+ import Page from "./Page.svelte";
4
+ import ChapterIDs from "../../models/book/ChapterID";
5
+ import DefinitionView from "./DefinitionView.svelte";
6
+ import { getUser, getEdition, isEditionEditable } from "./Contexts";
7
+ import Instructions from "./Instructions.svelte";
8
+ import Button from "../app/Button.svelte";
9
9
  let auth = getUser();
10
10
  let edition = getEdition();
11
11
  let editable = isEditionEditable();
12
- $: glossary = $edition?.getGlossary() ?? {};
13
- // Sort by canonical phrases
14
- $: keys =
15
- $edition === undefined
16
- ? []
17
- : glossary === undefined || Object.keys(glossary).length === 0
18
- ? null
19
- : Object.keys(glossary).sort((a, b) => glossary[a].phrase.localeCompare(glossary[b].phrase));
12
+ let glossary = $derived($edition?.getGlossary() ?? {});
13
+ let keys = $derived($edition === void 0 ? [] : glossary === void 0 || Object.keys(glossary).length === 0 ? null : Object.keys(glossary).sort(
14
+ (a, b) => glossary[a].phrase.localeCompare(glossary[b].phrase)
15
+ ));
20
16
  function addEmptyDefinition() {
21
- if ($edition === undefined)
22
- return;
23
- // Generate an ID.
24
- const letters = 'abcdefghijklmnopqrstuvwxyz'.split('');
25
- let id = '';
26
- while (id.length < 4 || $edition.hasDefinition(id))
27
- id = id + letters[Math.round(Math.random() * 26)];
28
- edition.set($edition.withDefinition(id, '', '', []));
17
+ if ($edition === void 0) return;
18
+ const letters = "abcdefghijklmnopqrstuvwxyz".split("");
19
+ let id = "";
20
+ while (id.length < 4 || $edition.hasDefinition(id))
21
+ id = id + letters[Math.round(Math.random() * 26)];
22
+ edition.set($edition.withDefinition(id, "", "", []));
29
23
  }
30
24
  </script>
31
25
 
@@ -54,17 +48,19 @@ function addEmptyDefinition() {
54
48
  )
55
49
  : undefined}
56
50
  >
57
- <Outline
58
- slot="outline"
59
- previous={$edition.getPreviousChapterID(
60
- ChapterIDs.GlossaryID,
61
- editable,
62
- )}
63
- next={$edition.getNextChapterID(
64
- ChapterIDs.GlossaryID,
65
- editable,
66
- )}
67
- />
51
+ {#snippet outline()}
52
+ <Outline
53
+
54
+ previous={$edition.getPreviousChapterID(
55
+ ChapterIDs.GlossaryID,
56
+ editable,
57
+ )}
58
+ next={$edition.getNextChapterID(
59
+ ChapterIDs.GlossaryID,
60
+ editable,
61
+ )}
62
+ />
63
+ {/snippet}
68
64
  </Header>
69
65
  {#if editable}
70
66
  <Instructions {editable}>
@@ -1,16 +1,3 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: Record<string, never>;
4
- events: {
5
- [evt: string]: CustomEvent<any>;
6
- };
7
- slots: {};
8
- exports?: {} | undefined;
9
- bindings?: string | undefined;
10
- };
11
- export type GlossaryProps = typeof __propDef.props;
12
- export type GlossaryEvents = typeof __propDef.events;
13
- export type GlossarySlots = typeof __propDef.slots;
14
- export default class Glossary extends SvelteComponent<GlossaryProps, GlossaryEvents, GlossarySlots> {
15
- }
16
- export {};
1
+ declare const Glossary: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type Glossary = ReturnType<typeof Glossary>;
3
+ export default Glossary;