bookish-press 0.7.1 → 0.8.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.
- package/README.md +8 -0
- package/dist/components/Auth.svelte +29 -39
- package/dist/components/Auth.svelte.d.ts +5 -17
- package/dist/components/BookPreview.svelte +14 -20
- package/dist/components/BookPreview.svelte.d.ts +6 -18
- package/dist/components/Link.svelte +19 -30
- package/dist/components/Link.svelte.d.ts +7 -20
- package/dist/components/app/BookList.svelte +2 -3
- package/dist/components/app/BookList.svelte.d.ts +6 -18
- package/dist/components/app/Button.svelte +12 -8
- package/dist/components/app/Button.svelte.d.ts +10 -23
- package/dist/components/app/Feedback.svelte +4 -4
- package/dist/components/app/Feedback.svelte.d.ts +6 -19
- package/dist/components/app/Head.svelte +2 -2
- package/dist/components/app/Head.svelte.d.ts +6 -19
- package/dist/components/app/Large.svelte +4 -1
- package/dist/components/app/Large.svelte.d.ts +5 -28
- package/dist/components/app/Lead.svelte +4 -1
- package/dist/components/app/Lead.svelte.d.ts +5 -28
- package/dist/components/app/Link.svelte +12 -9
- package/dist/components/app/Link.svelte.d.ts +9 -22
- package/dist/components/app/Options.svelte +8 -6
- package/dist/components/app/Options.svelte.d.ts +8 -20
- package/dist/components/app/Paragraph.svelte +2 -2
- package/dist/components/app/Paragraph.svelte.d.ts +6 -19
- package/dist/components/app/Section.svelte +4 -1
- package/dist/components/app/Section.svelte.d.ts +5 -28
- package/dist/components/app/Table.svelte +4 -1
- package/dist/components/app/Table.svelte.d.ts +5 -28
- package/dist/components/app/TextInput.svelte +10 -8
- package/dist/components/app/TextInput.svelte.d.ts +12 -23
- package/dist/components/chapter/Atom.svelte +4 -7
- package/dist/components/chapter/Atom.svelte.d.ts +6 -19
- package/dist/components/chapter/Block.svelte +21 -23
- package/dist/components/chapter/Block.svelte.d.ts +5 -17
- package/dist/components/chapter/Callout.svelte +3 -5
- package/dist/components/chapter/Callout.svelte.d.ts +5 -17
- package/dist/components/chapter/CaptionedCode.svelte +12 -14
- package/dist/components/chapter/CaptionedCode.svelte.d.ts +5 -17
- package/dist/components/chapter/ChapterBody.svelte +14 -17
- package/dist/components/chapter/ChapterBody.svelte.d.ts +7 -19
- package/dist/components/chapter/ChapterBody.test.d.ts +1 -0
- package/dist/components/chapter/ChapterBody.test.js +85 -0
- package/dist/components/chapter/Citations.svelte +39 -45
- package/dist/components/chapter/Citations.svelte.d.ts +5 -17
- package/dist/components/chapter/Code.svelte +158 -155
- package/dist/components/chapter/Code.svelte.d.ts +10 -23
- package/dist/components/chapter/Comment.svelte +30 -23
- package/dist/components/chapter/Comment.svelte.d.ts +5 -17
- package/dist/components/chapter/Definition.svelte +36 -34
- package/dist/components/chapter/Definition.svelte.d.ts +5 -17
- package/dist/components/chapter/Embed.svelte +78 -72
- package/dist/components/chapter/Embed.svelte.d.ts +8 -20
- package/dist/components/chapter/ErrorMessage.svelte +2 -4
- package/dist/components/chapter/ErrorMessage.svelte.d.ts +5 -17
- package/dist/components/chapter/Figure.svelte +22 -29
- package/dist/components/chapter/Figure.svelte.d.ts +9 -22
- package/dist/components/chapter/Footnote.svelte +40 -32
- package/dist/components/chapter/Footnote.svelte.d.ts +5 -17
- package/dist/components/chapter/Format.svelte +26 -41
- package/dist/components/chapter/Format.svelte.d.ts +7 -18
- package/dist/components/chapter/InlineCode.svelte +7 -8
- package/dist/components/chapter/InlineCode.svelte.d.ts +5 -17
- package/dist/components/chapter/Label.svelte +5 -11
- package/dist/components/chapter/Label.svelte.d.ts +5 -17
- package/dist/components/chapter/LineBreak.svelte +1 -3
- package/dist/components/chapter/LineBreak.svelte.d.ts +5 -17
- package/dist/components/chapter/Link.svelte +17 -23
- package/dist/components/chapter/Link.svelte.d.ts +5 -17
- package/dist/components/chapter/List.svelte +9 -9
- package/dist/components/chapter/List.svelte.d.ts +6 -17
- package/dist/components/chapter/Marginal.svelte +59 -60
- package/dist/components/chapter/Marginal.svelte.d.ts +10 -22
- package/dist/components/chapter/Paragraph.svelte +8 -23
- package/dist/components/chapter/Paragraph.svelte.d.ts +6 -18
- package/dist/components/chapter/Positioned.svelte +2 -4
- package/dist/components/chapter/Positioned.svelte.d.ts +6 -19
- package/dist/components/chapter/Problem.svelte +3 -2
- package/dist/components/chapter/Problem.svelte.d.ts +5 -28
- package/dist/components/chapter/Python.svelte +45 -58
- package/dist/components/chapter/Python.svelte.d.ts +6 -18
- package/dist/components/chapter/Quote.svelte +5 -7
- package/dist/components/chapter/Quote.svelte.d.ts +5 -17
- package/dist/components/chapter/Rule.svelte +1 -3
- package/dist/components/chapter/Rule.svelte.d.ts +5 -17
- package/dist/components/chapter/Table.svelte +6 -8
- package/dist/components/chapter/Table.svelte.d.ts +5 -17
- package/dist/components/chapter/Text.svelte +54 -69
- package/dist/components/chapter/Text.svelte.d.ts +6 -18
- package/dist/components/controls/DarkToggle.svelte +7 -8
- package/dist/components/controls/DarkToggle.svelte.d.ts +6 -18
- package/dist/components/editor/BookishEditor.svelte +583 -761
- package/dist/components/editor/BookishEditor.svelte.d.ts +14 -26
- package/dist/components/editor/CalloutEditor.svelte +3 -3
- package/dist/components/editor/CalloutEditor.svelte.d.ts +5 -17
- package/dist/components/editor/CaptionedCodeEditor.svelte +5 -5
- package/dist/components/editor/CaptionedCodeEditor.svelte.d.ts +5 -17
- package/dist/components/editor/CaretView.svelte +23 -25
- package/dist/components/editor/CaretView.svelte.d.ts +15 -27
- package/dist/components/editor/CitationsEditor.svelte +25 -28
- package/dist/components/editor/CitationsEditor.svelte.d.ts +5 -17
- package/dist/components/editor/ConfirmButton.svelte +9 -6
- package/dist/components/editor/ConfirmButton.svelte.d.ts +8 -21
- package/dist/components/editor/DefinitionEditor.svelte +11 -15
- package/dist/components/editor/DefinitionEditor.svelte.d.ts +5 -17
- package/dist/components/editor/EmbedEditor.svelte +43 -44
- package/dist/components/editor/EmbedEditor.svelte.d.ts +5 -17
- package/dist/components/editor/Icon.svelte +1 -1
- package/dist/components/editor/Icon.svelte.d.ts +5 -17
- package/dist/components/editor/ImageChooser.svelte +15 -18
- package/dist/components/editor/ImageChooser.svelte.d.ts +6 -18
- package/dist/components/editor/ImageThumbnail.svelte +29 -24
- package/dist/components/editor/ImageThumbnail.svelte.d.ts +7 -19
- package/dist/components/editor/InlineCodeEditor.svelte +3 -3
- package/dist/components/editor/InlineCodeEditor.svelte.d.ts +5 -17
- package/dist/components/editor/LabelEditor.svelte +5 -6
- package/dist/components/editor/LabelEditor.svelte.d.ts +5 -17
- package/dist/components/editor/LanguageEditor.svelte +4 -5
- package/dist/components/editor/LanguageEditor.svelte.d.ts +6 -18
- package/dist/components/editor/LinkEditor.svelte +52 -68
- package/dist/components/editor/LinkEditor.svelte.d.ts +5 -17
- package/dist/components/editor/Note.svelte +4 -1
- package/dist/components/editor/Note.svelte.d.ts +5 -28
- package/dist/components/editor/Permissions.svelte +55 -51
- package/dist/components/editor/Permissions.svelte.d.ts +9 -21
- package/dist/components/editor/PositionEditor.svelte +6 -7
- package/dist/components/editor/PositionEditor.svelte.d.ts +6 -18
- package/dist/components/editor/QuoteEditor.svelte +3 -3
- package/dist/components/editor/QuoteEditor.svelte.d.ts +5 -17
- package/dist/components/editor/Switch.svelte +16 -11
- package/dist/components/editor/Switch.svelte.d.ts +9 -21
- package/dist/components/editor/TableEditor.svelte +3 -3
- package/dist/components/editor/TableEditor.svelte.d.ts +5 -17
- package/dist/components/editor/TextEditor.svelte +74 -87
- package/dist/components/editor/TextEditor.svelte.d.ts +13 -25
- package/dist/components/editor/Toggle.svelte +18 -21
- package/dist/components/editor/Toggle.svelte.d.ts +7 -20
- package/dist/components/editor/Toolbar.svelte +140 -145
- package/dist/components/editor/Toolbar.svelte.d.ts +5 -17
- package/dist/components/editor/ToolbarGroup.svelte +4 -4
- package/dist/components/editor/ToolbarGroup.svelte.d.ts +6 -19
- package/dist/components/editor/ToolbarSpacer.svelte +1 -1
- package/dist/components/editor/ToolbarSpacer.svelte.d.ts +22 -21
- package/dist/components/editor/URLEditor.svelte +3 -5
- package/dist/components/editor/URLEditor.svelte.d.ts +7 -19
- package/dist/components/page/Acknowledgements.svelte +14 -8
- package/dist/components/page/Acknowledgements.svelte.d.ts +3 -16
- package/dist/components/page/Analytics.svelte +2 -3
- package/dist/components/page/Analytics.svelte.d.ts +6 -17
- package/dist/components/page/Authors.svelte +29 -29
- package/dist/components/page/Authors.svelte.d.ts +11 -23
- package/dist/components/page/BookLoader.svelte +47 -43
- package/dist/components/page/BookLoader.svelte.d.ts +5 -17
- package/dist/components/page/BulkReferenceEditor.svelte +43 -26
- package/dist/components/page/BulkReferenceEditor.svelte.d.ts +3 -16
- package/dist/components/page/Chapter.svelte +226 -250
- package/dist/components/page/Chapter.svelte.d.ts +6 -18
- package/dist/components/page/ChapterContext.d.ts +3 -1
- package/dist/components/page/ChapterNumber.svelte +4 -1
- package/dist/components/page/ChapterNumber.svelte.d.ts +5 -28
- package/dist/components/page/ChapterTitle.svelte +4 -4
- package/dist/components/page/ChapterTitle.svelte.d.ts +6 -19
- package/dist/components/page/Contexts.js +2 -2
- package/dist/components/page/DefinitionView.svelte +51 -44
- package/dist/components/page/DefinitionView.svelte.d.ts +6 -18
- package/dist/components/page/Description.svelte +10 -4
- package/dist/components/page/Description.svelte.d.ts +16 -14
- package/dist/components/page/EditableHeader.svelte +4 -6
- package/dist/components/page/EditableHeader.svelte.d.ts +7 -18
- package/dist/components/page/Edition.svelte +57 -71
- package/dist/components/page/Edition.svelte.d.ts +7 -20
- package/dist/components/page/EditionLoader.svelte +119 -82
- package/dist/components/page/EditionLoader.svelte.d.ts +6 -19
- package/dist/components/page/Editions.svelte +61 -41
- package/dist/components/page/Editions.svelte.d.ts +5 -17
- package/dist/components/page/Glossary.svelte +31 -35
- package/dist/components/page/Glossary.svelte.d.ts +3 -16
- package/dist/components/page/Header.svelte +43 -49
- package/dist/components/page/Header.svelte.d.ts +19 -30
- package/dist/components/page/Index.svelte +46 -46
- package/dist/components/page/Index.svelte.d.ts +3 -16
- package/dist/components/page/Instructions.svelte +2 -2
- package/dist/components/page/Instructions.svelte.d.ts +6 -19
- package/dist/components/page/License.svelte +13 -7
- package/dist/components/page/License.svelte.d.ts +16 -14
- package/dist/components/page/Loading.svelte +9 -9
- package/dist/components/page/Loading.svelte.d.ts +22 -21
- package/dist/components/page/Media.svelte +36 -27
- package/dist/components/page/Media.svelte.d.ts +3 -16
- package/dist/components/page/MediaPreview.svelte +22 -19
- package/dist/components/page/MediaPreview.svelte.d.ts +8 -21
- package/dist/components/page/Muted.svelte +4 -1
- package/dist/components/page/Muted.svelte.d.ts +5 -28
- package/dist/components/page/Outline.svelte +76 -97
- package/dist/components/page/Outline.svelte.d.ts +8 -20
- package/dist/components/page/Page.svelte +27 -35
- package/dist/components/page/Page.svelte.d.ts +7 -20
- package/dist/components/page/PageHeader.svelte +2 -2
- package/dist/components/page/PageHeader.svelte.d.ts +6 -19
- package/dist/components/page/PageParagraph.svelte +4 -1
- package/dist/components/page/PageParagraph.svelte.d.ts +5 -28
- package/dist/components/page/PossibleChapter.svelte +7 -7
- package/dist/components/page/PossibleChapter.svelte.d.ts +3 -16
- package/dist/components/page/PossibleReference.svelte +4 -5
- package/dist/components/page/PossibleReference.svelte.d.ts +6 -18
- package/dist/components/page/Print.svelte +18 -2
- package/dist/components/page/Print.svelte.d.ts +3 -16
- package/dist/components/page/Publish.svelte +47 -47
- package/dist/components/page/Publish.svelte.d.ts +3 -16
- package/dist/components/page/Reference.svelte +24 -35
- package/dist/components/page/Reference.svelte.d.ts +6 -18
- package/dist/components/page/References.svelte +21 -22
- package/dist/components/page/References.svelte.d.ts +3 -16
- package/dist/components/page/Rows.svelte +4 -1
- package/dist/components/page/Rows.svelte.d.ts +5 -28
- package/dist/components/page/Search.svelte +58 -60
- package/dist/components/page/Search.svelte.d.ts +3 -16
- package/dist/components/page/Status.svelte +2 -2
- package/dist/components/page/Status.svelte.d.ts +16 -14
- package/dist/components/page/SubdomainEditor.svelte +11 -11
- package/dist/components/page/SubdomainEditor.svelte.d.ts +16 -14
- package/dist/components/page/TableOfContents.svelte +143 -125
- package/dist/components/page/TableOfContents.svelte.d.ts +3 -16
- package/dist/components/page/TableOfContentsImage.svelte +6 -7
- package/dist/components/page/TableOfContentsImage.svelte.d.ts +6 -18
- package/dist/components/page/TableOfContentsRow.svelte +32 -32
- package/dist/components/page/TableOfContentsRow.svelte.d.ts +10 -22
- package/dist/components/page/ThemeEditor.svelte +35 -28
- package/dist/components/page/ThemeEditor.svelte.d.ts +3 -16
- package/dist/components/page/ThemeEditorPreview.svelte +11 -13
- package/dist/components/page/ThemeEditorPreview.svelte.d.ts +5 -17
- package/dist/components/page/ThemeSetEditor.svelte +4 -6
- package/dist/components/page/ThemeSetEditor.svelte.d.ts +7 -19
- package/dist/components/page/ThemeVariableEditor.svelte +9 -11
- package/dist/components/page/ThemeVariableEditor.svelte.d.ts +7 -19
- package/dist/components/page/Title.svelte +4 -1
- package/dist/components/page/Title.svelte.d.ts +5 -28
- package/dist/components/page/Unknown.svelte +11 -8
- package/dist/components/page/Unknown.svelte.d.ts +5 -17
- package/dist/models/CRUD.js +23 -4
- package/dist/models/Firebase.js +18 -4
- package/dist/models/book/Book.d.ts +1 -1
- package/dist/models/book/Book.js +4 -3
- package/dist/models/book/BookMedia.js +1 -2
- package/dist/models/book/Chapter.js +3 -2
- package/dist/models/book/Edition.d.ts +1 -1
- package/dist/models/book/Edition.js +5 -1
- package/dist/models/chapter/BlocksNode.js +3 -1
- package/dist/models/chapter/BlocksNode.test.js +5 -1
- package/dist/models/chapter/Node.test.js +2 -2
- package/package.json +36 -25
|
@@ -1,98 +1,135 @@
|
|
|
1
|
-
<script>import Loading from
|
|
2
|
-
import Edition from
|
|
3
|
-
import Feedback from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
14
|
-
let
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
editionUnsub();
|
|
22
|
-
if (chaptersUnsub)
|
|
23
|
-
chaptersUnsub();
|
|
47
|
+
if (editionUnsub) editionUnsub();
|
|
48
|
+
if (chaptersUnsub) chaptersUnsub();
|
|
24
49
|
}
|
|
25
50
|
function listen() {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
$: if ($edition) {
|
|
112
|
+
$effect.pre(() => {
|
|
113
|
+
if ($edition) {
|
|
81
114
|
for (const chapter of $edition.chapters) {
|
|
82
|
-
|
|
83
|
-
|
|
115
|
+
if (chapter.ref && chapter.text !== null)
|
|
116
|
+
chapterText.set(chapter.ref.id, chapter.text);
|
|
84
117
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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
|
-
|
|
147
|
+
{@render children?.()}
|
|
111
148
|
</Edition>
|
|
112
149
|
{/if}
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
5
|
+
declare const EditionLoader: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type EditionLoader = ReturnType<typeof EditionLoader>;
|
|
7
|
+
export default EditionLoader;
|
|
@@ -1,32 +1,54 @@
|
|
|
1
|
-
<script>import { createNewEdition } from
|
|
2
|
-
import Instructions from
|
|
3
|
-
import Note from
|
|
4
|
-
import { getBook, getUser, isBookEditable } from
|
|
5
|
-
import Button from
|
|
6
|
-
import Link from
|
|
7
|
-
import Format from
|
|
8
|
-
import Parser from
|
|
9
|
-
import Permissions from
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
book.set(await createNewEdition($book));
|
|
14
|
+
let publisher = $state(false);
|
|
15
|
+
async function updateUserClaims() {
|
|
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;
|
|
20
19
|
}
|
|
20
|
+
async function createEdition() {
|
|
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
|
+
}
|
|
28
|
+
}
|
|
29
|
+
let editions = $derived($book?.getEditions());
|
|
30
|
+
let latestPublishedID = $derived($book?.getLatestPublishedEditionID());
|
|
31
|
+
$effect(() => {
|
|
32
|
+
if ($user && $user.user) updateUserClaims();
|
|
33
|
+
});
|
|
21
34
|
</script>
|
|
22
35
|
|
|
23
36
|
{#if $book && editions}
|
|
24
37
|
{#if editable}
|
|
25
38
|
<p>
|
|
26
|
-
<Button
|
|
27
|
-
|
|
39
|
+
<Button
|
|
40
|
+
tooltip="create new edition"
|
|
41
|
+
command={createEdition}
|
|
42
|
+
disabled={!publisher}>+ edition</Button
|
|
28
43
|
>
|
|
29
44
|
</p>
|
|
45
|
+
{#if !publisher || !$book.hasPublishedEdition()}
|
|
46
|
+
<Note
|
|
47
|
+
>You must have publisher privileges to create new editions of a
|
|
48
|
+
published book. If you believe this is an error, please contact
|
|
49
|
+
support.</Note
|
|
50
|
+
>
|
|
51
|
+
{/if}
|
|
30
52
|
{/if}
|
|
31
53
|
<Instructions {editable}>
|
|
32
54
|
Each book has one or more editions, allowing you to track revisions and
|
|
@@ -36,18 +58,17 @@ async function handleDraftEdition() {
|
|
|
36
58
|
and then publish. By default, readers will see the latest published
|
|
37
59
|
edition, but they can access older editions here.
|
|
38
60
|
</Instructions>
|
|
39
|
-
{#each editions as edition
|
|
40
|
-
{@const editionNumber =
|
|
41
|
-
editions === undefined ? -1 : editions.length - index}
|
|
61
|
+
{#each editions.toReversed() as edition (edition.ref)}
|
|
62
|
+
{@const editionNumber = edition.number}
|
|
42
63
|
{@const editionLabel =
|
|
43
64
|
editionNumber +
|
|
44
65
|
(editionNumber === 1
|
|
45
66
|
? 'st'
|
|
46
67
|
: editionNumber === 2
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
68
|
+
? 'nd'
|
|
69
|
+
: editionNumber === 3
|
|
70
|
+
? 'rd'
|
|
71
|
+
: 'th')}
|
|
51
72
|
|
|
52
73
|
{#if $book && (editable || edition.published || ($user?.user?.uid && edition.editionuids.includes($user.user.uid)))}
|
|
53
74
|
<section class="edition">
|
|
@@ -55,38 +76,37 @@ async function handleDraftEdition() {
|
|
|
55
76
|
>{editionLabel}
|
|
56
77
|
<Note
|
|
57
78
|
>{#if edition.published}{new Date(
|
|
58
|
-
edition.published
|
|
79
|
+
edition.published,
|
|
59
80
|
).toLocaleDateString(
|
|
60
|
-
'en-us'
|
|
81
|
+
'en-us',
|
|
61
82
|
)}{:else}unpublished{/if}
|
|
62
83
|
{#if edition.published}
|
|
63
84
|
<Link
|
|
64
85
|
to={latestPublishedID === edition.ref.id &&
|
|
65
86
|
$book.getSubdomain() !== undefined
|
|
66
87
|
? `/${$book.getSubdomain()}`
|
|
67
|
-
: `/${$book.getID()}/${
|
|
68
|
-
editions.length - index
|
|
69
|
-
}`}
|
|
88
|
+
: `/${$book.getID()}/${editionNumber}`}
|
|
70
89
|
external>read</Link
|
|
71
90
|
>{/if}
|
|
72
91
|
{#if editable || ($user?.user?.uid && edition.editionuids.includes($user?.user.uid))}
|
|
73
92
|
|
|
74
93
|
<Link
|
|
75
|
-
to={`/write/${$book.getID()}/${
|
|
76
|
-
|
|
77
|
-
}`}>edit</Link
|
|
94
|
+
to={`/write/${$book.getID()}/${editionNumber}`}
|
|
95
|
+
>edit</Link
|
|
78
96
|
>
|
|
79
97
|
{/if}
|
|
80
98
|
</Note>
|
|
81
99
|
</h3>
|
|
82
|
-
<p
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
{#if edition.summary !== ''}<p
|
|
101
|
+
><em
|
|
102
|
+
><Format
|
|
103
|
+
node={Parser.parseFormat(
|
|
104
|
+
undefined,
|
|
105
|
+
edition.summary,
|
|
106
|
+
)}
|
|
107
|
+
/></em
|
|
108
|
+
></p
|
|
109
|
+
>{/if}
|
|
90
110
|
</section>
|
|
91
111
|
{/if}
|
|
92
112
|
{/each}
|
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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
|
|
2
|
-
import Outline from
|
|
3
|
-
import Page from
|
|
4
|
-
import ChapterIDs from
|
|
5
|
-
import DefinitionView from
|
|
6
|
-
import { getUser, getEdition, isEditionEditable } from
|
|
7
|
-
import Instructions from
|
|
8
|
-
import Button from
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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 {
|
|
2
|
-
|
|
3
|
-
|
|
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;
|