bookish-press 0.11.2 → 0.12.0

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 (93) hide show
  1. package/dist/components/chapter/Block.svelte +19 -0
  2. package/dist/components/chapter/Block.svelte.d.ts +1 -0
  3. package/dist/components/chapter/ChapterBody.test.js +69 -0
  4. package/dist/components/chapter/Format.svelte +4 -0
  5. package/dist/components/chapter/Marginal.svelte +2 -1
  6. package/dist/components/chapter/Symbol.svelte +27 -0
  7. package/dist/components/chapter/Symbol.svelte.d.ts +7 -0
  8. package/dist/components/editor/BookishEditor.svelte +41 -153
  9. package/dist/components/editor/Commands.js +45 -44
  10. package/dist/components/editor/Commands.test.d.ts +1 -0
  11. package/dist/components/editor/Commands.test.js +791 -0
  12. package/dist/components/editor/Editing.d.ts +51 -0
  13. package/dist/components/editor/Editing.js +201 -0
  14. package/dist/components/editor/Permissions.svelte +10 -2
  15. package/dist/components/page/BookLoader.svelte +43 -6
  16. package/dist/components/page/BulkReferenceEditor.svelte +2 -2
  17. package/dist/components/page/Chapter.svelte +77 -70
  18. package/dist/components/page/Contexts.d.ts +14 -0
  19. package/dist/components/page/Contexts.js +14 -4
  20. package/dist/components/page/Edition.svelte +2 -10
  21. package/dist/components/page/EditionLoader.svelte +40 -7
  22. package/dist/components/page/Index.svelte +1 -1
  23. package/dist/components/page/Publish.svelte +0 -42
  24. package/dist/components/page/Reference.svelte +2 -2
  25. package/dist/components/page/References.svelte +5 -6
  26. package/dist/components/page/TitlePage.svelte +65 -0
  27. package/dist/components/page/TitlePage.svelte.d.ts +20 -0
  28. package/dist/components/page/UnsavedNotice.svelte +96 -0
  29. package/dist/components/page/UnsavedNotice.svelte.d.ts +7 -0
  30. package/dist/epub/xhtml.js +15 -0
  31. package/dist/models/CRUD.d.ts +28 -12
  32. package/dist/models/CRUD.emu.test.d.ts +1 -0
  33. package/dist/models/CRUD.emu.test.js +250 -0
  34. package/dist/models/CRUD.js +110 -72
  35. package/dist/models/book/Book.js +1 -1
  36. package/dist/models/book/Book.test.d.ts +1 -0
  37. package/dist/models/book/Book.test.js +124 -0
  38. package/dist/models/book/BookMedia.d.ts +5 -0
  39. package/dist/models/book/BookMedia.js +23 -7
  40. package/dist/models/book/BookMedia.test.d.ts +1 -0
  41. package/dist/models/book/BookMedia.test.js +40 -0
  42. package/dist/models/book/Chapter.js +28 -12
  43. package/dist/models/book/Chapter.test.d.ts +1 -0
  44. package/dist/models/book/Chapter.test.js +167 -0
  45. package/dist/models/book/Edition.d.ts +2 -0
  46. package/dist/models/book/Edition.js +34 -25
  47. package/dist/models/book/Edition.test.d.ts +1 -0
  48. package/dist/models/book/Edition.test.js +342 -0
  49. package/dist/models/book/Reference.js +5 -9
  50. package/dist/models/book/Reference.test.d.ts +1 -0
  51. package/dist/models/book/Reference.test.js +40 -0
  52. package/dist/models/chapter/BlocksNode.d.ts +2 -0
  53. package/dist/models/chapter/BlocksNode.js +59 -3
  54. package/dist/models/chapter/BlocksNode.test.js +2 -2
  55. package/dist/models/chapter/Caret.js +12 -3
  56. package/dist/models/chapter/Caret.test.d.ts +1 -0
  57. package/dist/models/chapter/Caret.test.js +127 -0
  58. package/dist/models/chapter/ChapterNode.d.ts +3 -0
  59. package/dist/models/chapter/ChapterNode.js +11 -1
  60. package/dist/models/chapter/CommentNode.js +3 -2
  61. package/dist/models/chapter/EmbedNode.js +1 -1
  62. package/dist/models/chapter/FootnoteNode.js +1 -1
  63. package/dist/models/chapter/FormatNode.d.ts +5 -1
  64. package/dist/models/chapter/FormatNode.js +60 -20
  65. package/dist/models/chapter/LabelNode.js +4 -2
  66. package/dist/models/chapter/ListNode.js +11 -13
  67. package/dist/models/chapter/Node.test.js +2 -11
  68. package/dist/models/chapter/Operations.test.d.ts +1 -0
  69. package/dist/models/chapter/Operations.test.js +298 -0
  70. package/dist/models/chapter/ParagraphNode.js +29 -3
  71. package/dist/models/chapter/Parser.d.ts +49 -4
  72. package/dist/models/chapter/Parser.js +210 -88
  73. package/dist/models/chapter/Parser.test.js +31 -0
  74. package/dist/models/chapter/Roundtrip.test.d.ts +1 -0
  75. package/dist/models/chapter/Roundtrip.test.js +313 -0
  76. package/dist/models/chapter/SymbolBlockNode.d.ts +40 -0
  77. package/dist/models/chapter/SymbolBlockNode.js +75 -0
  78. package/dist/models/chapter/SymbolBlockNode.test.d.ts +1 -0
  79. package/dist/models/chapter/SymbolBlockNode.test.js +130 -0
  80. package/dist/models/chapter/SymbolNode.d.ts +32 -0
  81. package/dist/models/chapter/SymbolNode.js +61 -0
  82. package/dist/models/chapter/SymbolNode.test.d.ts +1 -0
  83. package/dist/models/chapter/SymbolNode.test.js +177 -0
  84. package/dist/models/chapter/TableNode.js +2 -2
  85. package/dist/models/chapter/TextNode.d.ts +8 -1
  86. package/dist/models/chapter/TextNode.js +22 -15
  87. package/dist/util/getSubdomain.js +5 -1
  88. package/dist/util/getSubdomain.test.d.ts +1 -0
  89. package/dist/util/getSubdomain.test.js +53 -0
  90. package/dist/util/mineReference.js +12 -5
  91. package/dist/util/mineReference.test.d.ts +1 -0
  92. package/dist/util/mineReference.test.js +62 -0
  93. package/package.json +12 -7
@@ -6,7 +6,7 @@ import { BASE, DARK_MODE, getBook } from "./Contexts";
6
6
  import { BookishTheme } from "../../models/book/Theme.js";
7
7
  import { isDark, setDark } from "../../util/dark";
8
8
  import { page } from "$app/state";
9
- import Title from "./Title.svelte";
9
+ import TitlePage from "./TitlePage.svelte";
10
10
  import Page from "./Page.svelte";
11
11
  import Parser from "../../models/chapter/Parser.js";
12
12
  import EmbedNode from "../../models/chapter/EmbedNode.js";
@@ -107,10 +107,7 @@ function toRules(set) {
107
107
  <!-- No edition to render? Coming soon. -->
108
108
  {:else if $book}
109
109
  <Page title={$book.title}>
110
- <div class="comingsoon">
111
- <Title>{$book.title}</Title>
112
- <p>Coming soon.</p>
113
- </div>
110
+ <TitlePage title={$book.title}>Coming soon.</TitlePage>
114
111
  </Page>
115
112
  {/if}
116
113
  </main>
@@ -138,9 +135,4 @@ function toRules(set) {
138
135
  z-index: 0;
139
136
  text-align: left;
140
137
  }
141
-
142
- .comingsoon {
143
- margin-top: 4em;
144
- text-align: center;
145
- }
146
138
  </style>
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">import Loading from "./Loading.svelte";
2
2
  import Edition from "./Edition.svelte";
3
- import Feedback from "../app/Feedback.svelte";
3
+ import TitlePage from "./TitlePage.svelte";
4
4
  import { getBook, getEdition, getStatus, getUser, getChapterText } from "./Contexts.js";
5
5
  import BookSaveStatus from "../../models/book/BookSaveStatus.js";
6
6
  import { get } from "svelte/store";
@@ -31,7 +31,7 @@ const statusWatch = status?.subscribe((current) => {
31
31
  });
32
32
  function skipStaleSnapshot() {
33
33
  const current = status ? get(status) : undefined;
34
- return locallyEdited && (current === BookSaveStatus.Changed || current === BookSaveStatus.Saving);
34
+ return locallyEdited && (current === BookSaveStatus.Changed || current === BookSaveStatus.Saving || current === BookSaveStatus.Error);
35
35
  }
36
36
  function applySnapshot(apply) {
37
37
  applyingSnapshot = true;
@@ -46,6 +46,15 @@ let chapterText = new Map();
46
46
  let editionUnsub = undefined;
47
47
  let chaptersUnsub = undefined;
48
48
  let error = $state(undefined);
49
+ const privateEdition = {
50
+ title: "A private edition",
51
+ message: "This edition is a draft that only its authors can open. If you should be one of them, ask the book’s owner to add you as an editor."
52
+ };
53
+ const failed = (code) => ({
54
+ title: "Couldn’t load this edition",
55
+ message: `Bookish couldn’t reach it (${code}). Check your connection and reload the page.`,
56
+ error: true
57
+ });
49
58
  function unsub() {
50
59
  // Unsubscribe to the old edition document if we were listening to one.
51
60
  if (editionUnsub) editionUnsub();
@@ -57,7 +66,10 @@ function listen() {
57
66
  // If we no longer have a book, we can't get an edition.
58
67
  if ($book === undefined) {
59
68
  edition.set(undefined);
60
- error = "Unknown book.";
69
+ error = {
70
+ title: "No book here",
71
+ message: "There’s no book at this address."
72
+ };
61
73
  return;
62
74
  } else {
63
75
  currentEditionID = page.params.editionid;
@@ -67,13 +79,19 @@ function listen() {
67
79
  if (currentEditionID === undefined) {
68
80
  if (latestPublished) {
69
81
  editionID = $book.getLatestPublishedEditionID();
70
- if (editionID === undefined) error = "There is no published edition of this book.";
82
+ if (editionID === undefined) error = {
83
+ title: $book.title,
84
+ message: "No edition of this book has been published yet."
85
+ };
71
86
  } else {
72
87
  editionID = $book.getLatestEditionID();
73
88
  }
74
89
  } else {
75
90
  editionID = $book.getEditionNumberID(parseFloat(currentEditionID));
76
- if (editionID === undefined) error = `There is no ${currentEditionID} edition of this book`;
91
+ if (editionID === undefined) error = {
92
+ title: `No edition ${currentEditionID}`,
93
+ message: `This book doesn’t have an edition ${currentEditionID}. Its other editions are listed on its contents page.`
94
+ };
77
95
  }
78
96
  // Listen to the doc for changes and listen to all of its chapters.
79
97
  if (editionID !== undefined) {
@@ -84,8 +102,16 @@ function listen() {
84
102
  applySnapshot(() => edition.set(ed.withChapterText(chapterText)));
85
103
  } else {
86
104
  applySnapshot(() => edition.set(undefined));
87
- error = "Unable to load edition";
105
+ error = {
106
+ title: "No edition here",
107
+ message: "This edition no longer exists. It may have been deleted."
108
+ };
88
109
  }
110
+ }, (e) => {
111
+ // Already loaded? Access was revoked mid-session; keep
112
+ // it on screen so unsaved edits can still be copied.
113
+ if (get(edition) !== undefined) return;
114
+ error = e.code === "permission-denied" ? privateEdition : failed(e.code);
89
115
  });
90
116
  chaptersUnsub = listenToChapters($book.getID(), editionID, (chapters) => {
91
117
  // Cache the text of the chapters we received — except
@@ -102,6 +128,9 @@ function listen() {
102
128
  if ($edition) {
103
129
  applySnapshot(() => edition.set($edition.withChapterText(chapterText)));
104
130
  }
131
+ }, (e) => {
132
+ if (get(edition) !== undefined) return;
133
+ error = e.code === "permission-denied" ? privateEdition : failed(e.code);
105
134
  });
106
135
  }
107
136
  }
@@ -135,7 +164,11 @@ onDestroy(() => {
135
164
  </script>
136
165
 
137
166
  {#if $book === undefined || error}
138
- <Feedback error>Unable to load edition: {error}</Feedback>
167
+ <TitlePage
168
+ title={error?.title ?? 'No book here'}
169
+ error={error?.error ?? false}
170
+ >{error?.message ?? 'There’s no book at this address.'}</TitlePage
171
+ >
139
172
  {:else if $edition === undefined}
140
173
  <Loading />
141
174
  {:else}
@@ -75,7 +75,7 @@ let words = $derived.by(() => {
75
75
  <p
76
76
  ><em
77
77
  >This index includes all words, excluding common English words,
78
- words with apostrophes, and words ending in -ly.</em
78
+ contractions, and words ending in -ly.</em
79
79
  ></p
80
80
  >
81
81
 
@@ -7,38 +7,9 @@ import Note from "../editor/Note.svelte";
7
7
  import Instructions from "./Instructions.svelte";
8
8
  import Link from "../Link.svelte";
9
9
  import { PUBLIC_CONTEXT } from "$app/env/public";
10
- import Button from "../app/Button.svelte";
11
- import Feedback from "../app/Feedback.svelte";
12
10
  let auth = getUser();
13
11
  let edition = getEdition();
14
12
  let editable = isEditionEditable();
15
- let publishing = false;
16
- let feedback = $state(undefined);
17
- let error = $state(undefined);
18
- let url = $state(undefined);
19
- async function requestPublish() {
20
- if ($edition) {
21
- publishing = true;
22
- error = undefined;
23
- feedback = "Binding the book, this could take a minute...";
24
- try {
25
- const { publish } = await import("../../models/CRUD");
26
- const result = await publish($edition);
27
- if (typeof result === "string") {
28
- error = result;
29
- feedback = undefined;
30
- } else {
31
- url = result.url;
32
- }
33
- } catch (err) {
34
- console.log(err);
35
- feedback = undefined;
36
- error = "Unable to bundle the book for download :(";
37
- } finally {
38
- publishing = false;
39
- }
40
- }
41
- }
42
13
  let publisher = $state(undefined);
43
14
  async function updateUserClaims() {
44
15
  if ($auth === undefined || $auth.user === null) return;
@@ -85,20 +56,7 @@ $effect(() => {
85
56
  )
86
57
  : undefined}
87
58
  />
88
- <!-- Disabled until we can find a way to properly build the book in a cloud function. -->
89
- <!-- <Button
90
- tooltip="Publish the book online"
91
- disabled={publishing}
92
- command={() => requestPublish()}>↓ download</Button
93
- > -->
94
59
  </div>
95
- {#if error}
96
- <Feedback error>{error}</Feedback>
97
- {:else if url}
98
- <p>Your book is <Link to={url}>ready for download</Link>.</p>
99
- {:else if feedback}
100
- <Feedback>{feedback}</Feedback>
101
- {/if}
102
60
  <div>
103
61
  <Note
104
62
  >{#if $edition.published}Last published {new Date(
@@ -3,11 +3,11 @@ import Button from "../app/Button.svelte";
3
3
  import Table from "../app/Table.svelte";
4
4
  import ConfirmButton from "../editor/ConfirmButton.svelte";
5
5
  import TextEditor from "../editor/TextEditor.svelte";
6
- import { getEdition, isEditionEditable } from "./Contexts";
6
+ import { getEdition, canEditReferences } from "./Contexts";
7
7
  import Link from "../Link.svelte";
8
8
  import Note from "../editor/Note.svelte";
9
9
  let { reference, edit = false } = $props();
10
- let editable = isEditionEditable();
10
+ let editable = canEditReferences();
11
11
  let edition = getEdition();
12
12
  let editing = $state(false);
13
13
  function startEditing() {
@@ -4,17 +4,17 @@ import Page from "./Page.svelte";
4
4
  import ChapterIDs from "../../models/book/ChapterID.js";
5
5
  import BulkReferenceEditor from "./BulkReferenceEditor.svelte";
6
6
  import PossibleReference from "./PossibleReference.svelte";
7
- import { getUser, getEdition, isEditionEditable } from "./Contexts";
7
+ import { getUser, getEdition, canEditReferences } from "./Contexts";
8
8
  let auth = getUser();
9
9
  let edition = getEdition();
10
- let editable = isEditionEditable();
10
+ let editable = canEditReferences();
11
11
  let references = $derived($edition?.hasReferences() ? $edition.getReferences() : null);
12
12
  </script>
13
13
 
14
14
  {#if $edition}
15
15
  <Page title={`${$edition.getTitle()} - References`}>
16
16
  <Header
17
- editable={isEditionEditable() ||
17
+ editable={canEditReferences() ||
18
18
  ($auth !== undefined &&
19
19
  $auth.user !== null &&
20
20
  $edition.isChapterEditor($auth.user.uid))}
@@ -37,8 +37,7 @@ let references = $derived($edition?.hasReferences() ? $edition.getReferences() :
37
37
  : undefined}
38
38
  >
39
39
  {#snippet outline()}
40
- <Outline
41
-
40
+ <Outline
42
41
  previous={$edition.getPreviousChapterID(
43
42
  ChapterIDs.ReferencesID,
44
43
  editable,
@@ -48,7 +47,7 @@ let references = $derived($edition?.hasReferences() ? $edition.getReferences() :
48
47
  editable,
49
48
  )}
50
49
  />
51
- {/snippet}
50
+ {/snippet}
52
51
  </Header>
53
52
  {#if editable}<BulkReferenceEditor />{/if}
54
53
  {#if references !== null}
@@ -0,0 +1,65 @@
1
+ <script lang="ts">let { title, error = false, children, actions } = $props();
2
+ export {};
3
+ </script>
4
+
5
+ <section class="title-page" class:error role={error ? 'alert' : undefined}>
6
+ <h1>{title}</h1>
7
+ {#if children}<p class="message">{@render children()}</p>{/if}
8
+ {#if actions}<p class="actions">{@render actions()}</p>{/if}
9
+ </section>
10
+
11
+ <style>
12
+ .title-page {
13
+ box-sizing: border-box;
14
+ max-width: 34em;
15
+ margin: 4em auto 0 auto;
16
+ padding: 0 var(--bookish-block-padding, 1rem);
17
+ text-align: center;
18
+ color: var(--bookish-paragraph-color, var(--app-font-color, inherit));
19
+ }
20
+
21
+ h1 {
22
+ margin: 0;
23
+ font-size: var(--bookish-title-font-size, 30pt);
24
+ font-family: var(
25
+ --bookish-header-font-family,
26
+ var(--app-font, 'Outfit', sans-serif)
27
+ );
28
+ font-weight: var(--bookish-header-font-weight, 700);
29
+ line-height: var(--bookish-header-line-height, 1.4em);
30
+ text-wrap: balance;
31
+ }
32
+
33
+ .error h1 {
34
+ color: var(--bookish-error-color, var(--app-error-color, #b00020));
35
+ }
36
+
37
+ p {
38
+ font-family: var(
39
+ --bookish-paragraph-font-family,
40
+ 'Noto Serif',
41
+ Georgia,
42
+ serif
43
+ );
44
+ font-size: var(--bookish-paragraph-font-size, 14pt);
45
+ font-weight: var(--bookish-paragraph-font-weight, 400);
46
+ line-height: var(--bookish-paragraph-line-height, 1.6);
47
+ text-wrap: pretty;
48
+ }
49
+
50
+ .actions {
51
+ font-family: var(
52
+ --bookish-header-font-family,
53
+ var(--app-font, 'Outfit', sans-serif)
54
+ );
55
+ }
56
+
57
+ /* Links look like links in a book, and in the app outside one. */
58
+ .title-page .actions :global(a) {
59
+ color: var(--bookish-link-color, var(--app-interactive-color, #1b499c));
60
+ text-decoration: none;
61
+ }
62
+ .title-page .actions :global(a:hover) {
63
+ text-decoration: underline;
64
+ }
65
+ </style>
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A full-page state that looks like a book's title page: a title, a
3
+ * sentence or two below it, and optional links. Used for drafts that are
4
+ * coming soon, and for pages that can't show a book (missing, private, or
5
+ * failed to load). Only genuine failures set `error`, which colors the
6
+ * title; missing and private books are not errors.
7
+ *
8
+ * Fonts come from the book's theme inside a book, and fall back to the
9
+ * app's otherwise, so it reads the same in the reader and the editor.
10
+ */
11
+ import type { Snippet } from 'svelte';
12
+ interface Props {
13
+ title: string;
14
+ error?: boolean;
15
+ children?: Snippet;
16
+ actions?: Snippet;
17
+ }
18
+ declare const TitlePage: import("svelte").Component<Props, {}, "">;
19
+ type TitlePage = ReturnType<typeof TitlePage>;
20
+ export default TitlePage;
@@ -0,0 +1,96 @@
1
+ <script lang="ts">/**
2
+ * Shown when Bookish refuses to save an author's edits (for example,
3
+ * because their access was revoked while they were writing). The edits
4
+ * are still on screen; this explains what happened and lets the author
5
+ * copy them before they're lost.
6
+ */
7
+ import Button from "../app/Button.svelte";
8
+ import { getUnsaved } from "./Contexts";
9
+ let { reload = () => location.reload() } = $props();
10
+ const unsaved = getUnsaved();
11
+ let copied = $state(false);
12
+ let fallback = $state(undefined);
13
+ let showFallback = $state(false);
14
+ let text = $derived(($unsaved?.chapters ?? []).map((chapter) => `${chapter.title}\n\n${chapter.text}`).join("\n\n\n"));
15
+ async function copy() {
16
+ try {
17
+ await navigator.clipboard.writeText(text);
18
+ copied = true;
19
+ } catch {
20
+ // Some browsers refuse the clipboard; offer the text to select.
21
+ showFallback = true;
22
+ }
23
+ }
24
+ $effect(() => {
25
+ if (showFallback && fallback) {
26
+ fallback.focus();
27
+ fallback.select();
28
+ }
29
+ });
30
+ </script>
31
+
32
+ {#if $unsaved}
33
+ <section class="unsaved" role="alert" aria-labelledby="unsaved-title">
34
+ <p id="unsaved-title">
35
+ <strong>Your latest changes couldn’t be saved</strong> because you
36
+ no longer have permission to edit
37
+ {$unsaved.chapters.length === 1
38
+ ? `“${$unsaved.chapters[0].title}”`
39
+ : 'these chapters'}. They’re still here; copy them before you
40
+ leave.
41
+ </p>
42
+ <div class="actions">
43
+ <Button tooltip="copy unsaved text" command={copy}
44
+ >{copied ? 'copied' : 'copy unsaved text'}</Button
45
+ >
46
+ <Button
47
+ tooltip="discard unsaved changes and reload"
48
+ command={reload}>discard and reload</Button
49
+ >
50
+ </div>
51
+ {#if showFallback}
52
+ <textarea
53
+ bind:this={fallback}
54
+ readonly
55
+ aria-label="Unsaved text"
56
+ rows="6">{text}</textarea
57
+ >
58
+ {/if}
59
+ </section>
60
+ {/if}
61
+
62
+ <style>
63
+ .unsaved {
64
+ box-sizing: border-box;
65
+ width: 100%;
66
+ max-width: 50em;
67
+ margin: var(--app-chrome-padding) auto;
68
+ padding: var(--app-chrome-padding);
69
+ padding-left: calc(2 * var(--app-chrome-padding));
70
+ /* The app's Instructions pattern (a rule down the left side), with
71
+ the rule in the error color as the notice's one red accent. */
72
+ border-left: var(--app-chrome-border-size) solid var(--app-error-color);
73
+ background: var(--app-background-color);
74
+ color: var(--app-font-color);
75
+ font-family: var(--app-font);
76
+ font-size: var(--app-chrome-font-size);
77
+ display: flex;
78
+ flex-direction: column;
79
+ gap: var(--app-chrome-padding);
80
+ }
81
+ p {
82
+ margin: 0;
83
+ }
84
+ strong {
85
+ font-weight: 700;
86
+ }
87
+ .actions {
88
+ display: flex;
89
+ flex-wrap: wrap;
90
+ gap: var(--app-chrome-padding);
91
+ }
92
+ textarea {
93
+ width: 100%;
94
+ font-family: var(--bookish-paragraph-font-family, serif);
95
+ }
96
+ </style>
@@ -0,0 +1,7 @@
1
+ interface Props {
2
+ /** Reloads the page; replaceable for tests. */
3
+ reload?: () => void;
4
+ }
5
+ declare const UnsavedNotice: import("svelte").Component<Props, {}, "">;
6
+ type UnsavedNotice = ReturnType<typeof UnsavedNotice>;
7
+ export default UnsavedNotice;
@@ -23,12 +23,14 @@ import FootnoteNode from '../models/chapter/FootnoteNode';
23
23
  import FormatNode from '../models/chapter/FormatNode';
24
24
  import InlineCodeNode from '../models/chapter/InlineCodeNode';
25
25
  import LabelNode from '../models/chapter/LabelNode';
26
+ import SymbolNode from '../models/chapter/SymbolNode';
26
27
  import LineBreakNode from '../models/chapter/LineBreakNode';
27
28
  import LinkNode from '../models/chapter/LinkNode';
28
29
  import ListNode from '../models/chapter/ListNode';
29
30
  import ParagraphNode from '../models/chapter/ParagraphNode';
30
31
  import QuoteNode from '../models/chapter/QuoteNode';
31
32
  import RuleNode from '../models/chapter/RuleNode';
33
+ import SymbolBlockNode from '../models/chapter/SymbolBlockNode';
32
34
  import TableNode from '../models/chapter/TableNode';
33
35
  import TextNode from '../models/chapter/TextNode';
34
36
  /**
@@ -120,6 +122,12 @@ function block_(node, local) {
120
122
  return table(node, local);
121
123
  if (node instanceof RuleNode)
122
124
  return '<hr/>';
125
+ // Lines of symbols expand to the blocks their definitions make.
126
+ if (node instanceof SymbolBlockNode)
127
+ return node
128
+ .getBlocks()
129
+ .map((b) => block_(b, local))
130
+ .join('\n');
123
131
  // Editorial comments and parse errors are for authors, not readers.
124
132
  if (node instanceof CommentNode || node instanceof ErrorNode)
125
133
  return '';
@@ -239,6 +247,13 @@ function inline(node, local) {
239
247
  if (node instanceof LabelNode)
240
248
  // An empty anchor, so links to this label resolve. toHTML() drops these.
241
249
  return `<span id="${escapeAttribute(node.getMeta())}"></span>`;
250
+ // Symbols expand to their definitions; undefined ones stay as written.
251
+ if (node instanceof SymbolNode) {
252
+ const definition = node.getDefinition();
253
+ return definition
254
+ ? inline(definition, local)
255
+ : escapeText(`@${node.getName()}`);
256
+ }
242
257
  // Editorial comments never reach readers.
243
258
  if (node instanceof CommentNode)
244
259
  return '';
@@ -1,19 +1,35 @@
1
- import { type DocumentReference } from 'firebase/firestore';
1
+ import { type DocumentReference, type FirestoreError } from 'firebase/firestore';
2
2
  import Edition from './book/Edition';
3
3
  import Book from './book/Book';
4
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;
5
+ /** Called when a listener fails, e.g. because the rules deny access or the
6
+ * connection is lost. Listeners stop after an error. */
7
+ export type ListenError = (error: FirestoreError) => void;
8
+ export declare function listenToPublishedBooks(react: (books: Book[]) => void, error?: ListenError): Unsubscribe;
9
+ export declare function listenToEditableBooks(userID: string, react: (books: Book[]) => void, error?: ListenError): Unsubscribe;
10
+ export declare function listenToPartiallyEditableBooks(userID: string, react: (books: Book[]) => void, error?: ListenError): Unsubscribe;
11
+ /**
12
+ * Listen to the books with the given subdomain that the current user may
13
+ * read: published ones, and drafts they collaborate on. That takes three
14
+ * queries, since rules can't prove an unconstrained domain query is safe;
15
+ * results are merged, and reported once each query has answered.
16
+ */
17
+ export declare function listenToBooksByName(name: string, react: (books: Book[]) => void, error?: ListenError): Unsubscribe;
18
+ export declare function listenToBookWithID(id: string, react: (book: Book | null) => void, error?: ListenError): Unsubscribe;
19
+ export declare function listenToEdition(bookID: string, editionID: string, react: (edition: Edition | null) => void, error?: ListenError): Unsubscribe;
20
+ export declare function listenToChapters(bookID: string, editionID: string, react: (chapters: [DocumentReference, string][]) => void, error?: ListenError): Unsubscribe;
12
21
  /** Hit the authentication database to get user emails. */
13
22
  export declare function getUserEmails(uids: string[]): Promise<Map<string, string> | null>;
14
23
  export declare function createUser(email: string): Promise<string | null>;
15
24
  export declare function createBook(userID: string): Promise<string>;
16
25
  export declare function createNewEdition(book: Book): Promise<Book>;
26
+ /**
27
+ * Take (lock) or release a lease on some content of an edition, so two
28
+ * people don't edit it at once. Only the edition's `active` field is written,
29
+ * in a transaction, so a lease can't overwrite edits made elsewhere since the
30
+ * edition was loaded, and can't be taken while someone else holds it.
31
+ * Returns whether the caller holds the lease afterwards.
32
+ */
17
33
  export declare function updateLock(edition: Edition, uid: string, content: string, lock: boolean): Promise<boolean>;
18
34
  /**
19
35
  * Persists the edition in the database, creating and deleting chapters as necessary.
@@ -21,8 +37,8 @@ export declare function updateLock(edition: Edition, uid: string, content: strin
21
37
  */
22
38
  export declare function updateEdition(book: Book, previousEdition: Edition | undefined, newEdition: Edition): Promise<Map<string, DocumentReference>>;
23
39
  export declare function updateBook(book: Book): Promise<void>;
40
+ /**
41
+ * Whether no book has claimed this subdomain yet. Drafts aren't readable by
42
+ * everyone, so this asks a function that can see every book.
43
+ */
24
44
  export declare function isSubdomainAvailable(subdomain: string): Promise<boolean>;
25
- export declare function getBookIDWithSubdomain(subdomain: string): Promise<string | null>;
26
- export declare function publish(edition: Edition): Promise<string | {
27
- url: string;
28
- }>;
@@ -0,0 +1 @@
1
+ export {};