bookish-press 0.11.2 → 0.12.1
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.
- package/dist/components/chapter/Block.svelte +19 -0
- package/dist/components/chapter/Block.svelte.d.ts +1 -0
- package/dist/components/chapter/ChapterBody.test.js +79 -0
- package/dist/components/chapter/Format.svelte +11 -1
- package/dist/components/chapter/Marginal.svelte +2 -1
- package/dist/components/chapter/Symbol.svelte +27 -0
- package/dist/components/chapter/Symbol.svelte.d.ts +7 -0
- package/dist/components/editor/BookishEditor.svelte +41 -153
- package/dist/components/editor/Commands.js +45 -44
- package/dist/components/editor/Commands.test.d.ts +1 -0
- package/dist/components/editor/Commands.test.js +791 -0
- package/dist/components/editor/Editing.d.ts +51 -0
- package/dist/components/editor/Editing.js +201 -0
- package/dist/components/editor/ImageChooser.svelte +8 -5
- package/dist/components/editor/ImageChooser.test.d.ts +1 -0
- package/dist/components/editor/ImageChooser.test.js +67 -0
- package/dist/components/editor/Permissions.svelte +10 -2
- package/dist/components/page/BookLoader.svelte +43 -6
- package/dist/components/page/BulkReferenceEditor.svelte +2 -2
- package/dist/components/page/Chapter.svelte +77 -70
- package/dist/components/page/Contexts.d.ts +14 -0
- package/dist/components/page/Contexts.js +14 -4
- package/dist/components/page/Edition.svelte +2 -10
- package/dist/components/page/EditionLoader.svelte +40 -7
- package/dist/components/page/Index.svelte +1 -1
- package/dist/components/page/Publish.svelte +0 -42
- package/dist/components/page/Reference.svelte +2 -2
- package/dist/components/page/References.svelte +5 -6
- package/dist/components/page/TitlePage.svelte +65 -0
- package/dist/components/page/TitlePage.svelte.d.ts +20 -0
- package/dist/components/page/UnsavedNotice.svelte +96 -0
- package/dist/components/page/UnsavedNotice.svelte.d.ts +7 -0
- package/dist/epub/xhtml.js +15 -0
- package/dist/models/CRUD.d.ts +28 -12
- package/dist/models/CRUD.emu.test.d.ts +1 -0
- package/dist/models/CRUD.emu.test.js +250 -0
- package/dist/models/CRUD.js +110 -72
- package/dist/models/book/Book.js +1 -1
- package/dist/models/book/Book.test.d.ts +1 -0
- package/dist/models/book/Book.test.js +124 -0
- package/dist/models/book/BookMedia.d.ts +5 -0
- package/dist/models/book/BookMedia.js +23 -7
- package/dist/models/book/BookMedia.test.d.ts +1 -0
- package/dist/models/book/BookMedia.test.js +40 -0
- package/dist/models/book/Chapter.js +28 -12
- package/dist/models/book/Chapter.test.d.ts +1 -0
- package/dist/models/book/Chapter.test.js +167 -0
- package/dist/models/book/Edition.d.ts +2 -0
- package/dist/models/book/Edition.js +34 -25
- package/dist/models/book/Edition.test.d.ts +1 -0
- package/dist/models/book/Edition.test.js +342 -0
- package/dist/models/book/Reference.js +5 -9
- package/dist/models/book/Reference.test.d.ts +1 -0
- package/dist/models/book/Reference.test.js +40 -0
- package/dist/models/book/Theme.js +34 -34
- package/dist/models/chapter/BlocksNode.d.ts +2 -0
- package/dist/models/chapter/BlocksNode.js +59 -3
- package/dist/models/chapter/BlocksNode.test.js +2 -2
- package/dist/models/chapter/Caret.js +12 -3
- package/dist/models/chapter/Caret.test.d.ts +1 -0
- package/dist/models/chapter/Caret.test.js +127 -0
- package/dist/models/chapter/ChapterNode.d.ts +3 -0
- package/dist/models/chapter/ChapterNode.js +11 -1
- package/dist/models/chapter/CommentNode.js +3 -2
- package/dist/models/chapter/EmbedNode.js +1 -1
- package/dist/models/chapter/FootnoteNode.js +1 -1
- package/dist/models/chapter/FormatNode.d.ts +5 -1
- package/dist/models/chapter/FormatNode.js +60 -20
- package/dist/models/chapter/LabelNode.js +4 -2
- package/dist/models/chapter/ListNode.js +11 -13
- package/dist/models/chapter/Node.test.js +2 -11
- package/dist/models/chapter/Operations.test.d.ts +1 -0
- package/dist/models/chapter/Operations.test.js +298 -0
- package/dist/models/chapter/ParagraphNode.js +29 -3
- package/dist/models/chapter/Parser.d.ts +49 -4
- package/dist/models/chapter/Parser.js +210 -88
- package/dist/models/chapter/Parser.test.js +31 -0
- package/dist/models/chapter/Roundtrip.test.d.ts +1 -0
- package/dist/models/chapter/Roundtrip.test.js +313 -0
- package/dist/models/chapter/SymbolBlockNode.d.ts +40 -0
- package/dist/models/chapter/SymbolBlockNode.js +75 -0
- package/dist/models/chapter/SymbolBlockNode.test.d.ts +1 -0
- package/dist/models/chapter/SymbolBlockNode.test.js +130 -0
- package/dist/models/chapter/SymbolNode.d.ts +32 -0
- package/dist/models/chapter/SymbolNode.js +61 -0
- package/dist/models/chapter/SymbolNode.test.d.ts +1 -0
- package/dist/models/chapter/SymbolNode.test.js +177 -0
- package/dist/models/chapter/TableNode.js +2 -2
- package/dist/models/chapter/TextNode.d.ts +8 -1
- package/dist/models/chapter/TextNode.js +22 -15
- package/dist/util/getSubdomain.js +5 -1
- package/dist/util/getSubdomain.test.d.ts +1 -0
- package/dist/util/getSubdomain.test.js +53 -0
- package/dist/util/mineReference.js +12 -5
- package/dist/util/mineReference.test.d.ts +1 -0
- package/dist/util/mineReference.test.js +62 -0
- package/package.json +12 -7
|
@@ -189,7 +189,9 @@ let editable = $derived(!print && (isBookEditable() || isEditionEditable() || is
|
|
|
189
189
|
{#if $edition}
|
|
190
190
|
<Page
|
|
191
191
|
afterLoaded={scrollToLastLocation}
|
|
192
|
-
title={print
|
|
192
|
+
title={print
|
|
193
|
+
? undefined
|
|
194
|
+
: `${$edition.getTitle()} - ${chapter.getTitle()}`}
|
|
193
195
|
>
|
|
194
196
|
<Header
|
|
195
197
|
{editable}
|
|
@@ -206,10 +208,12 @@ let editable = $derived(!print && (isBookEditable() || isEditionEditable() || is
|
|
|
206
208
|
>
|
|
207
209
|
<!-- Collapse the outline if a marginal is selected. -->
|
|
208
210
|
{#snippet outline()}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
+
<Outline
|
|
211
212
|
collapse={$marginal !== undefined}
|
|
212
|
-
previous={$edition.getPreviousChapterID(
|
|
213
|
+
previous={$edition.getPreviousChapterID(
|
|
214
|
+
chapterID,
|
|
215
|
+
editable,
|
|
216
|
+
)}
|
|
213
217
|
next={$edition.getNextChapterID(chapterID, editable)}
|
|
214
218
|
listener={(expanded) => {
|
|
215
219
|
// If the outline is being expanded, hide the marginal, otherwise leave it alone.
|
|
@@ -219,76 +223,74 @@ let editable = $derived(!print && (isBookEditable() || isEditionEditable() || is
|
|
|
219
223
|
hideOutlineIfObscured();
|
|
220
224
|
}}
|
|
221
225
|
/>
|
|
222
|
-
|
|
226
|
+
{/snippet}
|
|
223
227
|
<!-- Add an editable chapter ID if in editor mode -->
|
|
224
228
|
{#snippet before()}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
<
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
229
|
+
{#if editable && $book}
|
|
230
|
+
<Muted>
|
|
231
|
+
<em>bookish.press/book/</em><TextEditor
|
|
232
|
+
text={chapter.getID()}
|
|
233
|
+
label="Chapter URL ID editor"
|
|
234
|
+
save={// After the ID is edited, reload the page with the new URL.
|
|
235
|
+
async (newChapterID) => {
|
|
236
|
+
if ($book) {
|
|
237
|
+
setChapter(
|
|
238
|
+
edition,
|
|
239
|
+
chapter,
|
|
240
|
+
chapter.withChapterID(newChapterID),
|
|
241
|
+
);
|
|
242
|
+
// Navigate to the new ID
|
|
243
|
+
goto(
|
|
244
|
+
`/write/${$book.getID()}/${editionNumber}/${newChapterID}`,
|
|
245
|
+
{
|
|
246
|
+
reset: false,
|
|
247
|
+
},
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
}}
|
|
251
|
+
placeholder="chapter name"
|
|
252
|
+
valid={(newChapterID) =>
|
|
253
|
+
!/^[a-zA-Z0-9]+$/.test(newChapterID)
|
|
254
|
+
? 'Chapter IDs must be one or more letters or numbers'
|
|
255
|
+
: chapter.getID() !== newChapterID &&
|
|
256
|
+
$edition?.hasChapter(newChapterID)
|
|
257
|
+
? "There's already a chapter that has this ID."
|
|
258
|
+
: undefined}
|
|
259
|
+
saveOnExit={true}
|
|
260
|
+
/>
|
|
261
|
+
</Muted>
|
|
262
|
+
{/if}
|
|
263
|
+
{#if editable}
|
|
264
|
+
<Toggle
|
|
265
|
+
on={chapter.isNumbered()}
|
|
266
|
+
save={(on) =>
|
|
267
|
+
setChapter(
|
|
268
|
+
edition,
|
|
269
|
+
chapter,
|
|
270
|
+
chapter.asNumbered(on),
|
|
271
|
+
)}
|
|
272
|
+
>
|
|
273
|
+
<ChapterNumber
|
|
274
|
+
>{#if chapterNumber !== undefined}Chapter {chapterNumber}{:else}<Muted
|
|
275
|
+
>Unnumbered</Muted
|
|
276
|
+
>{/if}</ChapterNumber
|
|
269
277
|
>
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
{/if}
|
|
279
|
-
{#if chapterSection !== undefined && chapterSection.length > 0}
|
|
280
|
-
<span class="section-name">{chapterSection}</span>
|
|
281
|
-
{/if}
|
|
282
|
-
|
|
283
|
-
{/snippet}
|
|
278
|
+
</Toggle>
|
|
279
|
+
{:else if chapterNumber !== undefined}
|
|
280
|
+
<ChapterNumber>Chapter {chapterNumber}</ChapterNumber>
|
|
281
|
+
{/if}
|
|
282
|
+
{#if chapterSection !== undefined && chapterSection.length > 0}
|
|
283
|
+
<span class="section-name">{chapterSection}</span>
|
|
284
|
+
{/if}
|
|
285
|
+
{/snippet}
|
|
284
286
|
<!-- If there are chapter authors, render those, otherwise use the book authors -->
|
|
285
287
|
{#snippet after()}
|
|
286
|
-
|
|
288
|
+
<Authors
|
|
287
289
|
editable={isChapterEditable()}
|
|
288
|
-
|
|
289
290
|
authors={chapter.getAuthors()}
|
|
290
291
|
inheritedAuthors={$edition.getAuthors()}
|
|
291
|
-
add={() =>
|
|
292
|
+
add={() =>
|
|
293
|
+
setChapter(edition, chapter, chapter.withAuthor(''))}
|
|
292
294
|
edit={(index, text) =>
|
|
293
295
|
setChapter(
|
|
294
296
|
edition,
|
|
@@ -296,9 +298,13 @@ let editable = $derived(!print && (isBookEditable() || isEditionEditable() || is
|
|
|
296
298
|
chapter.withRenamedAuthor(index, text),
|
|
297
299
|
)}
|
|
298
300
|
remove={(index) =>
|
|
299
|
-
setChapter(
|
|
301
|
+
setChapter(
|
|
302
|
+
edition,
|
|
303
|
+
chapter,
|
|
304
|
+
chapter.withoutAuthor(index),
|
|
305
|
+
)}
|
|
300
306
|
/>
|
|
301
|
-
|
|
307
|
+
{/snippet}
|
|
302
308
|
</Header>
|
|
303
309
|
|
|
304
310
|
<Instructions {editable}>
|
|
@@ -335,8 +341,9 @@ let editable = $derived(!print && (isBookEditable() || isEditionEditable() || is
|
|
|
335
341
|
{:else}
|
|
336
342
|
<ChapterBody node={chapterAST} />
|
|
337
343
|
{/if}
|
|
338
|
-
|
|
339
|
-
|
|
344
|
+
<!-- No text yet: it streams in after the page loads, so show
|
|
345
|
+
nothing rather than an error while it does. -->
|
|
346
|
+
{/if}
|
|
340
347
|
</section>
|
|
341
348
|
|
|
342
349
|
{#if citations && citations.size > 0}
|
|
@@ -37,6 +37,9 @@ export declare function getRoot(): RootStore;
|
|
|
37
37
|
export declare function setChapter(store: EditionStore, previous: Chapter, revised: Chapter): void;
|
|
38
38
|
export declare function isChapterEditable(): boolean;
|
|
39
39
|
export declare function isEditionEditable(): boolean;
|
|
40
|
+
/** References are shared by every chapter, so chapter editors may edit them
|
|
41
|
+
* too, along with edition and book editors. */
|
|
42
|
+
export declare function canEditReferences(): boolean;
|
|
40
43
|
export declare function isEditionPartiallyEditable(): boolean;
|
|
41
44
|
export declare function isBookEditable(): boolean;
|
|
42
45
|
export declare const BASE: unique symbol;
|
|
@@ -47,6 +50,17 @@ export declare function getCaret(): Writable<CaretState | undefined>;
|
|
|
47
50
|
export declare const STATUS: unique symbol;
|
|
48
51
|
export type StatusStore = Writable<BookSaveStatus>;
|
|
49
52
|
export declare function getStatus(): StatusStore;
|
|
53
|
+
/** Text whose save was refused (for example, because access was revoked),
|
|
54
|
+
* kept so the author can copy it before leaving. */
|
|
55
|
+
export type UnsavedChanges = {
|
|
56
|
+
chapters: {
|
|
57
|
+
title: string;
|
|
58
|
+
text: string;
|
|
59
|
+
}[];
|
|
60
|
+
};
|
|
61
|
+
export declare const UNSAVED: unique symbol;
|
|
62
|
+
export type UnsavedStore = Writable<UnsavedChanges | undefined>;
|
|
63
|
+
export declare function getUnsaved(): UnsavedStore | undefined;
|
|
50
64
|
export declare const EDITORS: unique symbol;
|
|
51
65
|
export type EditorsStore = Writable<Map<string, string>>;
|
|
52
66
|
export declare function getEditors(): EditorsStore;
|
|
@@ -74,9 +74,12 @@ export function isEditionEditable() {
|
|
|
74
74
|
book !== undefined &&
|
|
75
75
|
auth !== undefined &&
|
|
76
76
|
auth.user !== null &&
|
|
77
|
-
(edition.isEditor(auth.user.uid) ||
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
(edition.isEditor(auth.user.uid) || book.isEditor(auth.user.uid)));
|
|
78
|
+
}
|
|
79
|
+
/** References are shared by every chapter, so chapter editors may edit them
|
|
80
|
+
* too, along with edition and book editors. */
|
|
81
|
+
export function canEditReferences() {
|
|
82
|
+
return isEditionEditable() || isEditionPartiallyEditable();
|
|
80
83
|
}
|
|
81
84
|
export function isEditionPartiallyEditable() {
|
|
82
85
|
if (!isRouteWrite())
|
|
@@ -110,6 +113,10 @@ export const STATUS = Symbol('status');
|
|
|
110
113
|
export function getStatus() {
|
|
111
114
|
return getContext(STATUS);
|
|
112
115
|
}
|
|
116
|
+
export const UNSAVED = Symbol('unsaved');
|
|
117
|
+
export function getUnsaved() {
|
|
118
|
+
return getContext(UNSAVED);
|
|
119
|
+
}
|
|
113
120
|
export const EDITORS = Symbol('editors');
|
|
114
121
|
export function getEditors() {
|
|
115
122
|
return getContext(EDITORS);
|
|
@@ -121,7 +128,10 @@ export async function lease(authStore, editionStore, contentID, lock) {
|
|
|
121
128
|
// Loaded here rather than at the top so bound books, which never
|
|
122
129
|
// lease, don't load Firebase. See FirebaseAvailable.ts.
|
|
123
130
|
const { updateLock } = await import('../../models/CRUD');
|
|
124
|
-
|
|
131
|
+
// Someone else may hold the lease; only record it locally if we got it.
|
|
132
|
+
const held = await updateLock(edition, auth.user.uid, contentID, lock);
|
|
133
|
+
if (lock && !held)
|
|
134
|
+
return false;
|
|
125
135
|
const latestEdition = get(editionStore);
|
|
126
136
|
const latestAuth = get(authStore);
|
|
127
137
|
if (latestEdition && latestAuth && latestAuth.user) {
|
|
@@ -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
|
|
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
|
-
<
|
|
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
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
<
|
|
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}
|
|
@@ -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,
|
|
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 =
|
|
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,
|
|
7
|
+
import { getUser, getEdition, canEditReferences } from "./Contexts";
|
|
8
8
|
let auth = getUser();
|
|
9
9
|
let edition = getEdition();
|
|
10
|
-
let editable =
|
|
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={
|
|
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
|
-
|
|
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
|
-
|
|
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;
|