bookish-press 0.4.0 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/components/Auth.svelte +27 -24
- package/components/Auth.svelte.d.ts +4 -4
- package/components/Authentication.d.ts +2 -2
- package/components/BookPreview.svelte +75 -59
- package/components/BookPreview.svelte.d.ts +5 -5
- package/components/External.svelte +1 -1
- package/components/External.svelte.d.ts +3 -3
- package/components/Link.svelte +49 -3
- package/components/Link.svelte.d.ts +3 -4
- package/components/app/BookList.svelte +19 -0
- package/components/app/BookList.svelte.d.ts +18 -0
- package/components/app/Button.svelte +49 -0
- package/components/app/Button.svelte.d.ts +22 -0
- package/components/app/Feedback.svelte +47 -0
- package/components/app/Feedback.svelte.d.ts +18 -0
- package/components/app/Head.svelte +15 -0
- package/components/app/Head.svelte.d.ts +18 -0
- package/components/app/Large.svelte +8 -0
- package/components/app/Large.svelte.d.ts +27 -0
- package/components/app/Lead.svelte +12 -0
- package/components/app/Lead.svelte.d.ts +27 -0
- package/components/app/Link.svelte +24 -0
- package/components/app/Link.svelte.d.ts +20 -0
- package/components/app/Options.svelte +24 -0
- package/components/app/Options.svelte.d.ts +19 -0
- package/components/app/Paragraph.svelte +20 -0
- package/components/app/Paragraph.svelte.d.ts +18 -0
- package/components/app/Section.svelte +12 -0
- package/components/app/Section.svelte.d.ts +27 -0
- package/components/app/Table.svelte +32 -0
- package/components/app/Table.svelte.d.ts +27 -0
- package/components/app/TextInput.svelte +38 -0
- package/components/app/TextInput.svelte.d.ts +22 -0
- package/components/chapter/Atom.svelte +20 -6
- package/components/chapter/Atom.svelte.d.ts +3 -3
- package/components/chapter/Block.svelte +26 -21
- package/components/chapter/Block.svelte.d.ts +4 -4
- package/components/chapter/Callout.svelte +38 -7
- package/components/chapter/Callout.svelte.d.ts +4 -4
- package/components/chapter/CaptionedCode.svelte +67 -24
- package/components/chapter/CaptionedCode.svelte.d.ts +4 -4
- package/components/chapter/ChapterBody.svelte +62 -9
- package/components/chapter/ChapterBody.svelte.d.ts +5 -4
- package/components/chapter/Citations.svelte +86 -20
- package/components/chapter/Citations.svelte.d.ts +4 -4
- package/components/chapter/Code.svelte +152 -21
- package/components/chapter/Code.svelte.d.ts +3 -3
- package/components/chapter/Comment.svelte +39 -17
- package/components/chapter/Comment.svelte.d.ts +3 -3
- package/components/chapter/Definition.svelte +52 -18
- package/components/chapter/Definition.svelte.d.ts +5 -8
- package/components/chapter/Embed.svelte +155 -67
- package/components/chapter/Embed.svelte.d.ts +6 -4
- package/components/chapter/ErrorMessage.svelte +7 -2
- package/components/chapter/ErrorMessage.svelte.d.ts +4 -4
- package/components/chapter/ExtendedPrism.d.ts +2 -0
- package/components/chapter/ExtendedPrism.js +69 -0
- package/components/chapter/Figure.svelte +90 -0
- package/components/chapter/Figure.svelte.d.ts +24 -0
- package/components/chapter/Footnote.svelte +75 -12
- package/components/chapter/Footnote.svelte.d.ts +4 -4
- package/components/chapter/Format.svelte +63 -38
- package/components/chapter/Format.svelte.d.ts +5 -4
- package/components/chapter/InlineCode.svelte +16 -6
- package/components/chapter/InlineCode.svelte.d.ts +4 -4
- package/components/chapter/Label.svelte +38 -9
- package/components/chapter/Label.svelte.d.ts +4 -4
- package/components/chapter/Link.svelte +24 -19
- package/components/chapter/Link.svelte.d.ts +4 -4
- package/components/chapter/List.svelte +75 -8
- package/components/chapter/List.svelte.d.ts +4 -4
- package/components/chapter/Marginal.svelte +169 -27
- package/components/chapter/Marginal.svelte.d.ts +6 -3
- package/components/chapter/Paragraph.svelte +79 -6
- package/components/chapter/Paragraph.svelte.d.ts +4 -4
- package/components/chapter/Positioned.svelte +33 -0
- package/components/chapter/Positioned.svelte.d.ts +19 -0
- package/components/chapter/Problem.svelte +15 -0
- package/components/chapter/Problem.svelte.d.ts +27 -0
- package/components/chapter/Python.svelte +68 -21
- package/components/chapter/Python.svelte.d.ts +4 -4
- package/components/chapter/Quote.svelte +64 -11
- package/components/chapter/Quote.svelte.d.ts +4 -4
- package/components/chapter/Rule.svelte +12 -1
- package/components/chapter/Rule.svelte.d.ts +4 -4
- package/components/chapter/Table.svelte +36 -25
- package/components/chapter/Table.svelte.d.ts +4 -4
- package/components/chapter/Text.svelte +61 -36
- package/components/chapter/Text.svelte.d.ts +5 -4
- package/components/editor/BookishEditor.svelte +373 -244
- package/components/editor/BookishEditor.svelte.d.ts +9 -6
- package/components/editor/CalloutEditor.svelte +5 -5
- package/components/editor/CalloutEditor.svelte.d.ts +4 -4
- package/components/editor/CaptionedCodeEditor.svelte +16 -12
- package/components/editor/CaptionedCodeEditor.svelte.d.ts +4 -4
- package/components/editor/CaretContext.d.ts +48 -16
- package/components/editor/CaretState.d.ts +16 -44
- package/components/editor/CaretUtilities.d.ts +2 -2
- package/components/editor/CaretView.svelte +82 -0
- package/components/editor/CaretView.svelte.d.ts +25 -0
- package/components/editor/CitationsEditor.svelte +36 -25
- package/components/editor/CitationsEditor.svelte.d.ts +4 -4
- package/components/editor/Clipboard.d.ts +2 -2
- package/components/editor/Command.d.ts +13 -12
- package/components/editor/Commands.d.ts +1 -1
- package/components/editor/Commands.js +1114 -571
- package/components/editor/ConfirmButton.svelte +18 -12
- package/components/editor/ConfirmButton.svelte.d.ts +5 -4
- package/components/editor/DefinitionEditor.svelte +29 -21
- package/components/editor/DefinitionEditor.svelte.d.ts +4 -4
- package/components/editor/EmbedEditor.svelte +93 -43
- package/components/editor/EmbedEditor.svelte.d.ts +3 -3
- package/components/editor/Icon.svelte +17 -0
- package/components/editor/Icon.svelte.d.ts +16 -0
- package/components/editor/ImageChooser.svelte +53 -34
- package/components/editor/ImageChooser.svelte.d.ts +3 -3
- package/components/editor/InlineCodeEditor.svelte +7 -4
- package/components/editor/InlineCodeEditor.svelte.d.ts +4 -4
- package/components/editor/LabelEditor.svelte +20 -11
- package/components/editor/LabelEditor.svelte.d.ts +4 -4
- package/components/editor/LanguageEditor.svelte +10 -7
- package/components/editor/LanguageEditor.svelte.d.ts +3 -3
- package/components/editor/LinkEditor.svelte +64 -39
- package/components/editor/LinkEditor.svelte.d.ts +4 -4
- package/components/editor/Note.svelte +4 -3
- package/components/editor/Note.svelte.d.ts +6 -2
- package/components/editor/Permissions.svelte +95 -0
- package/components/editor/Permissions.svelte.d.ts +20 -0
- package/components/editor/PositionEditor.svelte +9 -6
- package/components/editor/PositionEditor.svelte.d.ts +4 -4
- package/components/editor/QuoteEditor.svelte +7 -2
- package/components/editor/QuoteEditor.svelte.d.ts +4 -4
- package/components/editor/Switch.svelte +55 -28
- package/components/editor/Switch.svelte.d.ts +4 -4
- package/components/editor/TableEditor.svelte +10 -0
- package/components/editor/TableEditor.svelte.d.ts +17 -0
- package/components/editor/TextEditor.svelte +83 -45
- package/components/editor/TextEditor.svelte.d.ts +5 -4
- package/components/editor/Toggle.svelte +11 -8
- package/components/editor/Toggle.svelte.d.ts +4 -4
- package/components/editor/Toolbar.svelte +191 -144
- package/components/editor/Toolbar.svelte.d.ts +5 -8
- package/components/editor/ToolbarGroup.svelte +17 -23
- package/components/editor/ToolbarGroup.svelte.d.ts +3 -4
- package/components/editor/ToolbarSpacer.svelte +8 -1
- package/components/editor/ToolbarSpacer.svelte.d.ts +6 -2
- package/components/editor/URLEditor.svelte +6 -8
- package/components/editor/URLEditor.svelte.d.ts +3 -3
- package/components/editor/UndoState.d.ts +3 -3
- package/components/editor/icons/annotate.svg +1 -0
- package/components/editor/icons/block.svg +1 -0
- package/components/editor/icons/bold.svg +1 -0
- package/components/editor/icons/bullets.svg +1 -0
- package/components/editor/icons/callout.svg +1 -0
- package/components/editor/icons/citation.svg +8 -0
- package/components/editor/icons/clear.svg +1 -0
- package/components/editor/icons/clipboard.svg +1 -0
- package/components/editor/icons/code.svg +1 -0
- package/components/editor/icons/columnafter.svg +1 -0
- package/components/editor/icons/columnbefore.svg +1 -0
- package/components/editor/icons/comment.svg +1 -0
- package/components/editor/icons/copy.svg +1 -0
- package/components/editor/icons/cut.svg +1 -0
- package/components/editor/icons/define.svg +7 -0
- package/components/editor/icons/deletecolumn.svg +1 -0
- package/components/editor/icons/deleterow.svg +1 -0
- package/components/editor/icons/footnote.svg +8 -0
- package/components/editor/icons/header1.svg +7 -0
- package/components/editor/icons/header2.svg +7 -0
- package/components/editor/icons/header3.svg +7 -0
- package/components/editor/icons/home.svg +1 -0
- package/components/editor/icons/indent.svg +1 -0
- package/components/editor/icons/italic.svg +1 -0
- package/components/editor/icons/label.svg +1 -0
- package/components/editor/icons/left.svg +1 -0
- package/components/editor/icons/level.svg +1 -0
- package/components/editor/icons/link.svg +1 -0
- package/components/editor/icons/list.svg +1 -0
- package/components/editor/icons/media.svg +1 -0
- package/components/editor/icons/middle.svg +1 -0
- package/components/editor/icons/numbers.svg +10 -0
- package/components/editor/icons/paragraph.svg +1 -0
- package/components/editor/icons/paste.svg +10 -0
- package/components/editor/icons/quote.svg +1 -0
- package/components/editor/icons/redo.svg +1 -0
- package/components/editor/icons/right.svg +1 -0
- package/components/editor/icons/rowabove.svg +1 -0
- package/components/editor/icons/rowbelow.svg +1 -0
- package/components/editor/icons/rule.svg +1 -0
- package/components/editor/icons/sub.svg +1 -0
- package/components/editor/icons/super.svg +1 -0
- package/components/editor/icons/table.svg +1 -0
- package/components/editor/icons/text.svg +1 -0
- package/components/editor/icons/time.svg +1 -0
- package/components/editor/icons/undo.svg +1 -0
- package/components/editor/icons/unindent.svg +1 -0
- package/components/editor/icons/unlink.svg +1 -0
- package/components/page/Acknowledgements.svelte +35 -24
- package/components/page/Acknowledgements.svelte.d.ts +4 -4
- package/components/page/Authors.svelte +34 -17
- package/components/page/Authors.svelte.d.ts +7 -6
- package/components/page/BookLoader.svelte +59 -0
- package/components/page/BookLoader.svelte.d.ts +16 -0
- package/components/page/BulkReferenceEditor.svelte +54 -23
- package/components/page/BulkReferenceEditor.svelte.d.ts +4 -4
- package/components/page/Chapter.svelte +234 -143
- package/components/page/Chapter.svelte.d.ts +3 -3
- package/components/page/ChapterContext.d.ts +4 -4
- package/components/page/ChapterNumber.svelte +9 -0
- package/components/page/ChapterNumber.svelte.d.ts +27 -0
- package/components/page/ChapterTitle.svelte +16 -0
- package/components/page/ChapterTitle.svelte.d.ts +18 -0
- package/components/page/Contexts.d.ts +42 -22
- package/components/page/Contexts.js +129 -17
- package/components/page/DefinitionView.svelte +129 -90
- package/components/page/DefinitionView.svelte.d.ts +3 -3
- package/components/page/Description.svelte +31 -19
- package/components/page/Description.svelte.d.ts +4 -4
- package/components/page/Edition.svelte +135 -80
- package/components/page/Edition.svelte.d.ts +5 -6
- package/components/page/EditionLoader.svelte +99 -0
- package/components/page/EditionLoader.svelte.d.ts +18 -0
- package/components/page/Editions.svelte +106 -0
- package/components/page/Editions.svelte.d.ts +14 -0
- package/components/page/Glossary.svelte +65 -49
- package/components/page/Glossary.svelte.d.ts +4 -4
- package/components/page/Header.svelte +143 -56
- package/components/page/Header.svelte.d.ts +8 -6
- package/components/page/Index.svelte +116 -80
- package/components/page/Index.svelte.d.ts +4 -4
- package/components/page/Instructions.svelte +18 -17
- package/components/page/Instructions.svelte.d.ts +6 -4
- package/components/page/License.svelte +39 -23
- package/components/page/License.svelte.d.ts +4 -4
- package/components/page/Loading.svelte +102 -12
- package/components/page/Loading.svelte.d.ts +6 -2
- package/components/page/Media.svelte +81 -53
- package/components/page/Media.svelte.d.ts +4 -4
- package/components/page/MediaPreview.svelte +26 -8
- package/components/page/MediaPreview.svelte.d.ts +3 -3
- package/components/page/Muted.svelte +10 -0
- package/components/page/Muted.svelte.d.ts +27 -0
- package/components/page/Outline.svelte +279 -59
- package/components/page/Outline.svelte.d.ts +3 -3
- package/components/page/Page.svelte +40 -9
- package/components/page/Page.svelte.d.ts +3 -3
- package/components/page/PageHeader.svelte +14 -0
- package/components/page/PageHeader.svelte.d.ts +18 -0
- package/components/page/PageParagraph.svelte +18 -0
- package/components/page/PageParagraph.svelte.d.ts +27 -0
- package/components/page/PossibleChapter.svelte +7 -7
- package/components/page/PossibleChapter.svelte.d.ts +4 -4
- package/components/page/PossibleReference.svelte +6 -11
- package/components/page/PossibleReference.svelte.d.ts +6 -7
- package/components/page/Print.svelte +27 -3
- package/components/page/Print.svelte.d.ts +4 -4
- package/components/page/Publish.svelte +134 -0
- package/components/page/Publish.svelte.d.ts +14 -0
- package/components/page/Reference.svelte +259 -117
- package/components/page/Reference.svelte.d.ts +5 -5
- package/components/page/References.svelte +45 -48
- package/components/page/References.svelte.d.ts +4 -4
- package/components/page/Rows.svelte +54 -0
- package/components/page/Rows.svelte.d.ts +27 -0
- package/components/page/Search.svelte +88 -63
- package/components/page/Search.svelte.d.ts +4 -4
- package/components/page/Status.svelte +46 -39
- package/components/page/Status.svelte.d.ts +4 -9
- package/components/page/SubdomainEditor.svelte +41 -27
- package/components/page/SubdomainEditor.svelte.d.ts +4 -4
- package/components/page/TableOfContents.svelte +264 -191
- package/components/page/TableOfContents.svelte.d.ts +4 -4
- package/components/page/TableOfContentsImage.svelte +8 -8
- package/components/page/TableOfContentsImage.svelte.d.ts +3 -3
- package/components/page/TableOfContentsRow.svelte +97 -34
- package/components/page/TableOfContentsRow.svelte.d.ts +4 -4
- package/components/page/ThemeEditor.svelte +177 -39
- package/components/page/ThemeEditor.svelte.d.ts +4 -4
- package/components/page/ThemeEditorPreview.svelte +35 -23
- package/components/page/ThemeEditorPreview.svelte.d.ts +5 -5
- package/components/page/ThemeSetEditor.svelte +15 -13
- package/components/page/ThemeSetEditor.svelte.d.ts +4 -4
- package/components/page/ThemeVariableEditor.svelte +24 -15
- package/components/page/ThemeVariableEditor.svelte.d.ts +3 -3
- package/components/page/Title.svelte +12 -0
- package/components/page/Title.svelte.d.ts +27 -0
- package/components/page/Unknown.svelte +28 -21
- package/components/page/Unknown.svelte.d.ts +4 -4
- package/components/page/margins.js +50 -33
- package/index.d.ts +13 -0
- package/index.js +14 -0
- package/models/CRUD.d.ts +27 -0
- package/models/CRUD.js +262 -0
- package/models/Firebase.d.ts +1 -0
- package/models/Firebase.js +26 -16
- package/models/book/Book.d.ts +40 -39
- package/models/book/Book.js +121 -121
- package/models/book/BookMedia.d.ts +3 -3
- package/models/book/BookMedia.js +22 -16
- package/models/book/BookSaveStatus.d.ts +7 -0
- package/models/book/BookSaveStatus.js +8 -0
- package/models/book/Chapter.d.ts +50 -39
- package/models/book/Chapter.js +189 -198
- package/models/book/ChapterID.js +7 -7
- package/models/book/Definition.d.ts +1 -1
- package/models/book/Edition.d.ts +87 -61
- package/models/book/Edition.js +460 -309
- package/models/book/Reference.d.ts +24 -0
- package/models/book/Reference.js +78 -0
- package/models/book/Schema.d.ts +168 -0
- package/models/book/Schema.js +115 -0
- package/models/book/Theme.d.ts +44 -37
- package/models/book/Theme.js +452 -52
- package/models/book/ThemeColors.d.ts +1 -1
- package/models/book/Words.d.ts +2 -0
- package/models/book/Words.js +110 -0
- package/models/chapter/AtomNode.d.ts +4 -4
- package/models/chapter/AtomNode.js +20 -13
- package/models/chapter/BlockNode.d.ts +9 -10
- package/models/chapter/BlockNode.js +32 -13
- package/models/chapter/BlocksNode.d.ts +10 -10
- package/models/chapter/BlocksNode.js +315 -120
- package/models/chapter/BlocksNode.test.js +494 -228
- package/models/chapter/Bookkeeping.d.ts +1 -1
- package/models/chapter/CalloutNode.d.ts +3 -3
- package/models/chapter/CalloutNode.js +34 -12
- package/models/chapter/Caret.d.ts +9 -7
- package/models/chapter/Caret.js +11 -6
- package/models/chapter/ChapterNode.d.ts +11 -11
- package/models/chapter/ChapterNode.js +70 -33
- package/models/chapter/CitationsNode.d.ts +3 -3
- package/models/chapter/CitationsNode.js +31 -12
- package/models/chapter/CodeNode.d.ts +11 -6
- package/models/chapter/CodeNode.js +143 -34
- package/models/chapter/CommentNode.d.ts +5 -5
- package/models/chapter/CommentNode.js +29 -13
- package/models/chapter/DefinitionNode.d.ts +2 -2
- package/models/chapter/DefinitionNode.js +15 -7
- package/models/chapter/Edit.d.ts +3 -3
- package/models/chapter/EmbedNode.d.ts +9 -5
- package/models/chapter/EmbedNode.js +108 -35
- package/models/chapter/ErrorNode.d.ts +2 -2
- package/models/chapter/ErrorNode.js +34 -12
- package/models/chapter/FootnoteNode.d.ts +5 -5
- package/models/chapter/FootnoteNode.js +34 -16
- package/models/chapter/FormatNode.d.ts +10 -10
- package/models/chapter/FormatNode.js +237 -106
- package/models/chapter/FormatNode.test.js +87 -45
- package/models/chapter/InlineCodeNode.d.ts +2 -2
- package/models/chapter/InlineCodeNode.js +22 -9
- package/models/chapter/LabelNode.d.ts +4 -4
- package/models/chapter/LabelNode.js +31 -13
- package/models/chapter/LinkNode.d.ts +2 -2
- package/models/chapter/LinkNode.js +21 -9
- package/models/chapter/ListNode.d.ts +8 -8
- package/models/chapter/ListNode.js +99 -38
- package/models/chapter/ListNode.test.js +29 -24
- package/models/chapter/MetadataNode.d.ts +3 -3
- package/models/chapter/MetadataNode.js +13 -5
- package/models/chapter/Node.d.ts +5 -3
- package/models/chapter/Node.js +76 -29
- package/models/chapter/Node.test.js +20 -18
- package/models/chapter/ParagraphNode.d.ts +6 -6
- package/models/chapter/ParagraphNode.js +84 -29
- package/models/chapter/ParagraphNode.test.js +22 -13
- package/models/chapter/Parser.d.ts +27 -27
- package/models/chapter/Parser.js +220 -206
- package/models/chapter/Parser.test.js +16 -16
- package/models/chapter/Position.d.ts +1 -1
- package/models/chapter/QuoteNode.d.ts +6 -6
- package/models/chapter/QuoteNode.js +61 -23
- package/models/chapter/RootNode.d.ts +4 -4
- package/models/chapter/RuleNode.d.ts +2 -2
- package/models/chapter/RuleNode.js +31 -11
- package/models/chapter/TableNode.d.ts +8 -6
- package/models/chapter/TableNode.js +89 -34
- package/models/chapter/TableNode.test.js +22 -24
- package/models/chapter/TextNode.d.ts +6 -6
- package/models/chapter/TextNode.js +72 -32
- package/models/chapter/TextNode.test.js +4 -4
- package/package.json +108 -26
- package/util/getSubdomain.js +8 -6
- package/util/isMobile.js +1 -1
- package/util/mineReference.d.ts +3 -2
- package/util/mineReference.js +67 -29
- package/util/scrollToEyeLevel.js +6 -1
- package/components/chapter/renderPosition.d.ts +0 -3
- package/components/chapter/renderPosition.js +0 -4
- package/components/editor/ToolbarIcon.svelte +0 -22
- package/components/editor/ToolbarIcon.svelte.d.ts +0 -16
- package/components/page/Alert.svelte +0 -11
- package/components/page/Alert.svelte.d.ts +0 -23
- package/components/page/Revisions.svelte +0 -124
- package/components/page/Revisions.svelte.d.ts +0 -14
- package/models/BookLoader.d.ts +0 -2
- package/models/BookLoader.js +0 -67
- package/models/Firestore.d.ts +0 -22
- package/models/Firestore.js +0 -194
- package/models/chapter/ReferenceNode.d.ts +0 -29
- package/models/chapter/ReferenceNode.js +0 -48
- package/models/loadEdition.d.ts +0 -5
- package/models/loadEdition.js +0 -16
package/util/scrollToEyeLevel.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
let scrollToEyeLevel = (el) => {
|
|
2
2
|
// Top of the target minus a third of window height.
|
|
3
|
-
window.scrollTo({
|
|
3
|
+
window.scrollTo({
|
|
4
|
+
top: el.getBoundingClientRect().top +
|
|
5
|
+
window.scrollY -
|
|
6
|
+
window.innerHeight / 3,
|
|
7
|
+
behavior: 'smooth',
|
|
8
|
+
});
|
|
4
9
|
};
|
|
5
10
|
export default scrollToEyeLevel;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
<script>// If ends with .svg, its mapped to an asset in /svg/, otherwise just the text is displayed.
|
|
2
|
-
export let name;
|
|
3
|
-
</script>
|
|
4
|
-
|
|
5
|
-
<span>
|
|
6
|
-
{#if name.endsWith(".svg")}
|
|
7
|
-
<img alt={`${name.replace(".svg", "")} icon`} src="/svg/{name}"/>
|
|
8
|
-
{:else}
|
|
9
|
-
{name}
|
|
10
|
-
{/if}
|
|
11
|
-
</span>
|
|
12
|
-
|
|
13
|
-
<style>
|
|
14
|
-
span {
|
|
15
|
-
margin-right: var(--bookish-app-chrome-padding);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
img {
|
|
19
|
-
width: 1em;
|
|
20
|
-
height: 1em;
|
|
21
|
-
}
|
|
22
|
-
</style>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
declare const __propDef: {
|
|
3
|
-
props: {
|
|
4
|
-
name: string;
|
|
5
|
-
};
|
|
6
|
-
events: {
|
|
7
|
-
[evt: string]: CustomEvent<any>;
|
|
8
|
-
};
|
|
9
|
-
slots: {};
|
|
10
|
-
};
|
|
11
|
-
export declare type ToolbarIconProps = typeof __propDef.props;
|
|
12
|
-
export declare type ToolbarIconEvents = typeof __propDef.events;
|
|
13
|
-
export declare type ToolbarIconSlots = typeof __propDef.slots;
|
|
14
|
-
export default class ToolbarIcon extends SvelteComponentTyped<ToolbarIconProps, ToolbarIconEvents, ToolbarIconSlots> {
|
|
15
|
-
}
|
|
16
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/** @typedef {typeof __propDef.props} AlertProps */
|
|
2
|
-
/** @typedef {typeof __propDef.events} AlertEvents */
|
|
3
|
-
/** @typedef {typeof __propDef.slots} AlertSlots */
|
|
4
|
-
export default class Alert extends SvelteComponentTyped<{}, {
|
|
5
|
-
[evt: string]: CustomEvent<any>;
|
|
6
|
-
}, {
|
|
7
|
-
default: {};
|
|
8
|
-
}> {
|
|
9
|
-
}
|
|
10
|
-
export type AlertProps = typeof __propDef.props;
|
|
11
|
-
export type AlertEvents = typeof __propDef.events;
|
|
12
|
-
export type AlertSlots = typeof __propDef.slots;
|
|
13
|
-
import { SvelteComponentTyped } from "svelte";
|
|
14
|
-
declare const __propDef: {
|
|
15
|
-
props: {};
|
|
16
|
-
events: {
|
|
17
|
-
[evt: string]: CustomEvent<any>;
|
|
18
|
-
};
|
|
19
|
-
slots: {
|
|
20
|
-
default: {};
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
export {};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
<script>import Parser from "../../models/chapter/Parser";
|
|
2
|
-
import { addDraftInFirestore, publishDraftInFirestore } from "../../models/Firestore";
|
|
3
|
-
import Format from "../chapter/Format.svelte";
|
|
4
|
-
import BookishEditor from "../editor/BookishEditor.svelte";
|
|
5
|
-
import Switch from "../editor/Switch.svelte";
|
|
6
|
-
import Instructions from "./Instructions.svelte";
|
|
7
|
-
import Note from "../editor/Note.svelte";
|
|
8
|
-
import { getEdition, isEditable } from "./Contexts";
|
|
9
|
-
let edition = getEdition();
|
|
10
|
-
let editable = isEditable();
|
|
11
|
-
$: book = $edition.getBook();
|
|
12
|
-
// Legacy revisions
|
|
13
|
-
$: editionRevisions = $edition.getRevisions();
|
|
14
|
-
// Book revisions
|
|
15
|
-
$: bookRevisions = book?.getRevisions();
|
|
16
|
-
// Copy the current draft to create a new draft.
|
|
17
|
-
function handlePublish(index, published) {
|
|
18
|
-
if (book === undefined)
|
|
19
|
-
return;
|
|
20
|
-
publishDraftInFirestore(book, index, published);
|
|
21
|
-
}
|
|
22
|
-
function handleDraftEdition() {
|
|
23
|
-
if (book === undefined)
|
|
24
|
-
return;
|
|
25
|
-
addDraftInFirestore(book);
|
|
26
|
-
}
|
|
27
|
-
</script>
|
|
28
|
-
|
|
29
|
-
{#if editionRevisions.length > 0 }
|
|
30
|
-
<h2 class="bookish-header" id="revisions">Revisions</h2>
|
|
31
|
-
<ul>
|
|
32
|
-
{#each editionRevisions as revision }
|
|
33
|
-
<li><em>{revision[0]}</em>. <Format node={Parser.parseFormat($edition, revision[1])} /></li>
|
|
34
|
-
{/each}
|
|
35
|
-
</ul>
|
|
36
|
-
{/if}
|
|
37
|
-
{#if book && bookRevisions}
|
|
38
|
-
<h2 class="bookish-header" id="revisions">Editions {#if editable}<button on:click={handleDraftEdition}>+</button>{/if}</h2>
|
|
39
|
-
<Instructions>
|
|
40
|
-
Each book has one or more editions, allowing you to track revisions and ensure previous versions remain available.
|
|
41
|
-
When you're ready to revise, make a new edition, then publish it when you're done.
|
|
42
|
-
The edition with a * is the default edition readers will see, unless they explicitly choose to view a previous edition.
|
|
43
|
-
</Instructions>
|
|
44
|
-
<table class="bookish-table">
|
|
45
|
-
<colgroup>
|
|
46
|
-
<col width="5%" />
|
|
47
|
-
<col width="5%" />
|
|
48
|
-
<col width="50%" />
|
|
49
|
-
<col width="35%" />
|
|
50
|
-
</colgroup>
|
|
51
|
-
<tbody>
|
|
52
|
-
{#each bookRevisions as revision, index}
|
|
53
|
-
{@const editionNumber = bookRevisions === undefined ? -1 : bookRevisions.length - index }
|
|
54
|
-
{@const viewing = revision.ref.id === $edition.getRef()?.id }
|
|
55
|
-
|
|
56
|
-
{#if editable || revision.published}
|
|
57
|
-
<tr
|
|
58
|
-
class={`${!revision.published ? "bookish-edition-hidden" : ""} ${viewing ? "bookish-edition-editing": ""} `}
|
|
59
|
-
>
|
|
60
|
-
<td>
|
|
61
|
-
<em>{ editionNumber + (editionNumber === 1 ? "st" : editionNumber === 2 ? "nd" : editionNumber === 3 ? "rd" : "th") }</em> <Note>{(new Date(revision.time).toLocaleDateString("en-us"))}</Note>
|
|
62
|
-
</td>
|
|
63
|
-
<td>
|
|
64
|
-
{#if editable }
|
|
65
|
-
{#if viewing }
|
|
66
|
-
Editing
|
|
67
|
-
{:else}
|
|
68
|
-
<a href={`/write/${book.ref.id}/${bookRevisions.length - index}`}>Edit</a>
|
|
69
|
-
{/if}
|
|
70
|
-
{:else}
|
|
71
|
-
{#if viewing }
|
|
72
|
-
Viewing
|
|
73
|
-
{:else}
|
|
74
|
-
<a href={`/read/${book.ref.id}/${bookRevisions.length - index}`}>View</a>
|
|
75
|
-
{/if}
|
|
76
|
-
{/if}
|
|
77
|
-
</td>
|
|
78
|
-
<td>
|
|
79
|
-
{ #if editable }
|
|
80
|
-
<BookishEditor
|
|
81
|
-
ast={Parser.parseFormat(undefined, revision.summary).withTextIfEmpty()}
|
|
82
|
-
save={ newSummary => book ? book.setEditionChangeSummary(newSummary.toBookdown(), index) : undefined }
|
|
83
|
-
chapter={false}
|
|
84
|
-
component={Format}
|
|
85
|
-
placeholder="Summarize this edition's changes."
|
|
86
|
-
/>
|
|
87
|
-
{:else}
|
|
88
|
-
{#if revision.summary === ""}
|
|
89
|
-
<em>No summary of changes</em>
|
|
90
|
-
{:else}
|
|
91
|
-
{ revision.summary }
|
|
92
|
-
{/if}
|
|
93
|
-
{/if}
|
|
94
|
-
</td>
|
|
95
|
-
<td style="whitespace: nowrap">
|
|
96
|
-
{#if editable}
|
|
97
|
-
<Switch
|
|
98
|
-
position=">"
|
|
99
|
-
options={["hidden", "published"]}
|
|
100
|
-
enabled={revision.published || revision.summary !== ""}
|
|
101
|
-
value={revision.published ? "published" : "hidden"}
|
|
102
|
-
edit={ published => handlePublish(index, published === "published") }
|
|
103
|
-
/>
|
|
104
|
-
{#if revision === bookRevisions.find(e => e.published)}*{/if}
|
|
105
|
-
{/if}
|
|
106
|
-
</td>
|
|
107
|
-
</tr>
|
|
108
|
-
{/if}
|
|
109
|
-
{/each}
|
|
110
|
-
</tbody>
|
|
111
|
-
</table>
|
|
112
|
-
{/if}
|
|
113
|
-
|
|
114
|
-
<style>
|
|
115
|
-
.bookish-edition-hidden {
|
|
116
|
-
background: repeating-linear-gradient(
|
|
117
|
-
45deg,
|
|
118
|
-
var(--bookish-app-background),
|
|
119
|
-
var(--bookish-app-background) 10px,
|
|
120
|
-
var(--bookish-app-chrome-background) 10px,
|
|
121
|
-
var(--bookish-app-chrome-background) 20px
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
</style>
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
declare const __propDef: {
|
|
3
|
-
props: {};
|
|
4
|
-
events: {
|
|
5
|
-
[evt: string]: CustomEvent<any>;
|
|
6
|
-
};
|
|
7
|
-
slots: {};
|
|
8
|
-
};
|
|
9
|
-
export declare type RevisionsProps = typeof __propDef.props;
|
|
10
|
-
export declare type RevisionsEvents = typeof __propDef.events;
|
|
11
|
-
export declare type RevisionsSlots = typeof __propDef.slots;
|
|
12
|
-
export default class Revisions extends SvelteComponentTyped<RevisionsProps, RevisionsEvents, RevisionsSlots> {
|
|
13
|
-
}
|
|
14
|
-
export {};
|
package/models/BookLoader.d.ts
DELETED
package/models/BookLoader.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import Ajv from 'ajv';
|
|
2
|
-
import addFormats from 'ajv-formats';
|
|
3
|
-
import Edition from './book/Edition';
|
|
4
|
-
import schema from "../../schemas/book.json";
|
|
5
|
-
// Returns a Promise that, given a URL to
|
|
6
|
-
// 1) a to a valid "book.json" (see /src/schemas/book.json for a validity spec),
|
|
7
|
-
// 2) a "chapters" folder with .md files corresponding to the chapter IDs in the spec,
|
|
8
|
-
// resolves to a Book object with all of the book data.
|
|
9
|
-
// If any errors are encountered, throws an Error.
|
|
10
|
-
export default async function loadBookFromURL(url) {
|
|
11
|
-
let specification = undefined;
|
|
12
|
-
// Fetch the JSON from the given URL
|
|
13
|
-
return fetch(url + "book.json")
|
|
14
|
-
// If there's a valid response, get the JSON
|
|
15
|
-
.then(response => {
|
|
16
|
-
// If it's a valid status, parse the text as JSON.
|
|
17
|
-
if (response.status >= 200 && response.status <= 299)
|
|
18
|
-
return response.json();
|
|
19
|
-
// Otherwise, throw an error with the request failure.
|
|
20
|
-
else
|
|
21
|
-
throw Error(response.statusText);
|
|
22
|
-
})
|
|
23
|
-
// If the JSON doesn't parse...
|
|
24
|
-
.catch(() => {
|
|
25
|
-
throw Error("The book.json file that we received doesn't appear to be a JSON-formatted document.");
|
|
26
|
-
})
|
|
27
|
-
// Validate the specification and then load its chapters...
|
|
28
|
-
.then((book) => {
|
|
29
|
-
// Validate the book schema before we get started.
|
|
30
|
-
const ajv = new Ajv({
|
|
31
|
-
strictTuples: false
|
|
32
|
-
});
|
|
33
|
-
addFormats(ajv);
|
|
34
|
-
// Did the specification have schema errors?
|
|
35
|
-
// Initialize the book as null and set the errors.
|
|
36
|
-
if (!ajv.validate(schema, book)) {
|
|
37
|
-
throw Error("The book specification has validation errors" +
|
|
38
|
-
(ajv.errors ?
|
|
39
|
-
": " + ajv.errors.map(error => url + error.instancePath + " " + error.message).join("\n") :
|
|
40
|
-
"."));
|
|
41
|
-
}
|
|
42
|
-
// Remember the book spec
|
|
43
|
-
specification = book;
|
|
44
|
-
// Map all non-forthcoming chapters to a list of fetch promises
|
|
45
|
-
return Promise.all(specification.chapters.filter((chapter) => !chapter.forthcoming).map((chapter) => fetch(url + "chapters/" + chapter.id + ".md")
|
|
46
|
-
.then((response) => {
|
|
47
|
-
// If we got a reasonable response, process the chapter.
|
|
48
|
-
if (response.ok)
|
|
49
|
-
return response.text();
|
|
50
|
-
else
|
|
51
|
-
throw Error("Unable to load chapter named '" + chapter.id + "'. Make sure the chapter ID and chapter file name match.");
|
|
52
|
-
})
|
|
53
|
-
// Set the text field of the chapter object in the specification
|
|
54
|
-
.then((text) => {
|
|
55
|
-
chapter.text = text;
|
|
56
|
-
})
|
|
57
|
-
// If there's an error, set chapter text to null.
|
|
58
|
-
.catch(() => {
|
|
59
|
-
chapter.text = undefined;
|
|
60
|
-
})));
|
|
61
|
-
})
|
|
62
|
-
// After all the chapter loading promises are done, make the book.
|
|
63
|
-
.then(() => {
|
|
64
|
-
// Construct a Book object given the spec and chapter text
|
|
65
|
-
return new Edition(undefined, undefined, specification);
|
|
66
|
-
});
|
|
67
|
-
}
|
package/models/Firestore.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { DocumentReference } from "firebase/firestore";
|
|
2
|
-
import Edition from "./book/Edition";
|
|
3
|
-
import Book from "./book/Book";
|
|
4
|
-
import type Chapter from "./book/Chapter";
|
|
5
|
-
import type { ChapterContent } from "./book/Chapter";
|
|
6
|
-
export declare const loadPublishedBooksFromFirestore: () => Promise<Book[]>;
|
|
7
|
-
export declare const loadUsersBooksFromFirestore: (userID: string) => Promise<Book[] | null>;
|
|
8
|
-
export declare const getBookFromIDOrName: (bookIDOrName: string) => Promise<Book | null>;
|
|
9
|
-
export declare const loadBookFromFirestore: (bookID: string) => Promise<Book | null>;
|
|
10
|
-
export declare const loadEditionFromFirestore: (book: Book, editionID: string) => Promise<Edition>;
|
|
11
|
-
export declare const createBookInFirestore: (userID: string) => Promise<string>;
|
|
12
|
-
export declare const addDraftInFirestore: (book: Book) => Promise<void>;
|
|
13
|
-
export declare const publishDraftInFirestore: (book: Book, index: number, published: boolean) => Promise<void>;
|
|
14
|
-
export declare const updateEditionInFirestore: (edition: Edition) => Promise<void>;
|
|
15
|
-
export declare const deleteEditionInFirestore: (book: Book, index: number) => Promise<void>;
|
|
16
|
-
export declare const updateBookInFirestore: (book: Book) => Promise<void>;
|
|
17
|
-
export declare const addChapterInFirestore: (edition: DocumentReference, chapter: ChapterContent) => Promise<DocumentReference>;
|
|
18
|
-
export declare const removeChapterFromEditionInFirestore: (chapter: Chapter) => Promise<void>;
|
|
19
|
-
export declare const loadChapterTextFromFirestore: (chapter: DocumentReference) => Promise<ChapterContent>;
|
|
20
|
-
export declare const updateChapterTextInFirestore: (edition: DocumentReference, chapter: DocumentReference, text: string) => Promise<void>;
|
|
21
|
-
export declare const subdomainIsAvailable: (subdomain: string, book: Book) => Promise<boolean>;
|
|
22
|
-
export declare const getBookIDFromBookName: (subdomain: string) => Promise<string>;
|
package/models/Firestore.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { db } from "./Firebase";
|
|
2
|
-
import { collection, getDocs, getDoc, setDoc, doc, addDoc, query, where, deleteDoc, DocumentReference } from "firebase/firestore";
|
|
3
|
-
import Edition from "./book/Edition";
|
|
4
|
-
import Book from "./book/Book";
|
|
5
|
-
export const loadPublishedBooksFromFirestore = async () => {
|
|
6
|
-
if (!db)
|
|
7
|
-
throw Error("Can't retrieve books, not connected to the database.");
|
|
8
|
-
try {
|
|
9
|
-
const data = await getDocs(collection(db, "books"));
|
|
10
|
-
return data.docs.map(doc => new Book(doc.ref, doc.data())).filter(book => book.hasPublishedEdition());
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
throw Error("Couldn't load books, problem reading from the database.");
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
export const loadUsersBooksFromFirestore = async (userID) => {
|
|
17
|
-
if (!db)
|
|
18
|
-
throw Error("Can't retrieve user's books, not connected to Firebase.");
|
|
19
|
-
try {
|
|
20
|
-
const books = await getDocs(query(collection(db, "books"), where("uids", "array-contains", userID)));
|
|
21
|
-
return books.docs.map(doc => new Book(doc.ref, doc.data()));
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
console.error(err);
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
export const getBookFromIDOrName = async (bookIDOrName) => {
|
|
29
|
-
const book = await loadBookFromFirestore(bookIDOrName);
|
|
30
|
-
if (book)
|
|
31
|
-
return book;
|
|
32
|
-
const bookID = await getBookIDFromBookName(bookIDOrName);
|
|
33
|
-
return loadBookFromFirestore(bookID);
|
|
34
|
-
};
|
|
35
|
-
export const loadBookFromFirestore = async (bookID) => {
|
|
36
|
-
if (!db)
|
|
37
|
-
return null;
|
|
38
|
-
const bookRef = doc(db, "books", bookID);
|
|
39
|
-
const book = await getDoc(bookRef);
|
|
40
|
-
return !book.exists() ? null : new Book(bookRef, book.data());
|
|
41
|
-
};
|
|
42
|
-
export const loadEditionFromFirestore = async (book, editionID) => {
|
|
43
|
-
if (!db)
|
|
44
|
-
throw Error("Can't retrieve edition, not connected to Firebase.");
|
|
45
|
-
const edition = await getDoc(doc(db, "editions", editionID));
|
|
46
|
-
if (edition.exists())
|
|
47
|
-
return new Edition(book, edition.ref, edition.data());
|
|
48
|
-
else
|
|
49
|
-
throw Error("" + editionID + " doesn't exist");
|
|
50
|
-
};
|
|
51
|
-
export const createBookInFirestore = async (userID) => {
|
|
52
|
-
if (!db)
|
|
53
|
-
throw Error("Can't create book, not connected to Firebase.");
|
|
54
|
-
// Make a new empty edition with a single chapter.
|
|
55
|
-
const newEdition = new Edition();
|
|
56
|
-
// Add the current user to the book
|
|
57
|
-
newEdition.addUserID(userID);
|
|
58
|
-
// Add the book to the editions collection
|
|
59
|
-
const editionRef = await addDoc(collection(db, "editions"), newEdition.toObject());
|
|
60
|
-
newEdition.setRef(editionRef);
|
|
61
|
-
// Add a new chapter to the edition and update it in the database.
|
|
62
|
-
await newEdition.addChapter();
|
|
63
|
-
await updateEditionInFirestore(newEdition);
|
|
64
|
-
// Note that we don't create a sub-collection of chapters here.
|
|
65
|
-
// Firestore creates sub-collections automatically when documents are added.
|
|
66
|
-
// Create a new book with the draft first edition and the user ID.
|
|
67
|
-
const newBook = {
|
|
68
|
-
title: "",
|
|
69
|
-
authors: [],
|
|
70
|
-
description: "",
|
|
71
|
-
cover: null,
|
|
72
|
-
revisions: [
|
|
73
|
-
{
|
|
74
|
-
ref: editionRef,
|
|
75
|
-
time: Date.now(),
|
|
76
|
-
summary: "",
|
|
77
|
-
published: false
|
|
78
|
-
}
|
|
79
|
-
],
|
|
80
|
-
uids: [userID]
|
|
81
|
-
};
|
|
82
|
-
// Create the book
|
|
83
|
-
const bookRef = await addDoc(collection(db, "books"), newBook);
|
|
84
|
-
// Return the book id
|
|
85
|
-
return bookRef.id;
|
|
86
|
-
};
|
|
87
|
-
export const addDraftInFirestore = async (book) => {
|
|
88
|
-
if (!db)
|
|
89
|
-
throw Error("Can't publish draft, no Firebase connection.");
|
|
90
|
-
// Get the latest draft.
|
|
91
|
-
const latestDraft = await book.getDraftEdition();
|
|
92
|
-
if (latestDraft === undefined)
|
|
93
|
-
return;
|
|
94
|
-
// Create a copy of the existing draft as a new edition
|
|
95
|
-
const newDraft = await addDoc(collection(db, "editions"), latestDraft.toObject());
|
|
96
|
-
// Put the new edition in the book.
|
|
97
|
-
const revisions = book.getRevisions();
|
|
98
|
-
revisions.unshift({
|
|
99
|
-
ref: newDraft,
|
|
100
|
-
time: Date.now(),
|
|
101
|
-
summary: "",
|
|
102
|
-
published: false
|
|
103
|
-
});
|
|
104
|
-
book.setRevisions(revisions);
|
|
105
|
-
// Return the revised Book for viewing
|
|
106
|
-
updateBookInFirestore(book);
|
|
107
|
-
};
|
|
108
|
-
export const publishDraftInFirestore = async (book, index, published) => {
|
|
109
|
-
if (!db)
|
|
110
|
-
throw Error("Can't publish draft, no Firebase connection.");
|
|
111
|
-
// Update the edition's published status.
|
|
112
|
-
book.setPublished(published, index);
|
|
113
|
-
// Update the book with the latest published edition's metadata.
|
|
114
|
-
const draft = await book.getLatestPublishedEdition();
|
|
115
|
-
if (draft)
|
|
116
|
-
book.updateMetadataFromEdition(draft);
|
|
117
|
-
// Return the revised Book for viewing
|
|
118
|
-
updateBookInFirestore(book);
|
|
119
|
-
};
|
|
120
|
-
export const updateEditionInFirestore = async (edition) => {
|
|
121
|
-
if (!db)
|
|
122
|
-
throw Error("Can't update edition, not connected to Firebase.");
|
|
123
|
-
// Get the object for the edition so we can store it.
|
|
124
|
-
const spec = edition.toObject();
|
|
125
|
-
const editionRef = edition.getRef();
|
|
126
|
-
// Make sure the given edition has a database reference ID
|
|
127
|
-
if (!editionRef)
|
|
128
|
-
throw Error("Book given has no ID");
|
|
129
|
-
// Update the edition's document.
|
|
130
|
-
await setDoc(doc(db, "editions", editionRef.id), spec);
|
|
131
|
-
// Get the book of the editiion, and if the edition updated is the latest edition,
|
|
132
|
-
// update the book's cache of title, cover, authors, and description.
|
|
133
|
-
if (edition.book !== undefined && edition.isLatestPublishedEdition())
|
|
134
|
-
edition.book.updateMetadataFromEdition(edition);
|
|
135
|
-
};
|
|
136
|
-
export const deleteEditionInFirestore = async (book, index) => {
|
|
137
|
-
if (!db)
|
|
138
|
-
throw Error("Can't update edition, not connected to Firebase.");
|
|
139
|
-
const revisions = book.getRevisions();
|
|
140
|
-
if (index < 0 || index >= revisions.length)
|
|
141
|
-
return;
|
|
142
|
-
await deleteDoc(revisions[index].ref);
|
|
143
|
-
revisions.splice(index, 1);
|
|
144
|
-
book.setRevisions(revisions);
|
|
145
|
-
await updateBookInFirestore(book);
|
|
146
|
-
};
|
|
147
|
-
export const updateBookInFirestore = async (book) => {
|
|
148
|
-
if (!db)
|
|
149
|
-
throw Error("Can't update boo, not connected to Firebase.");
|
|
150
|
-
await setDoc(doc(db, "books", book.getRefID()), book.toObject());
|
|
151
|
-
};
|
|
152
|
-
export const addChapterInFirestore = async (edition, chapter) => {
|
|
153
|
-
if (!db)
|
|
154
|
-
throw Error("Can't add chapter, not connected to Firebase.");
|
|
155
|
-
return await addDoc(collection(db, `editions/${edition.id}/chapters`), chapter);
|
|
156
|
-
};
|
|
157
|
-
export const removeChapterFromEditionInFirestore = async (chapter) => {
|
|
158
|
-
if (!db)
|
|
159
|
-
throw Error("Can't add chapter, not connected to Firebase.");
|
|
160
|
-
const ref = chapter.getRef();
|
|
161
|
-
if (!ref)
|
|
162
|
-
throw Error("Can't delete chapter, it doesn't have a document ID.");
|
|
163
|
-
await deleteDoc(ref);
|
|
164
|
-
};
|
|
165
|
-
export const loadChapterTextFromFirestore = async (chapter) => {
|
|
166
|
-
if (!db)
|
|
167
|
-
throw Error("Not connected to Firebase.");
|
|
168
|
-
const text = await getDoc(chapter);
|
|
169
|
-
if (!text.exists())
|
|
170
|
-
throw Error("Chapter text does not exist.");
|
|
171
|
-
return text.data();
|
|
172
|
-
};
|
|
173
|
-
export const updateChapterTextInFirestore = async (edition, chapter, text) => {
|
|
174
|
-
if (!db)
|
|
175
|
-
throw Error("Can't update chapter, not connected to Firebase.");
|
|
176
|
-
// Get the object for the book so we can store it.
|
|
177
|
-
const spec = { text: text };
|
|
178
|
-
// Update the book's preview
|
|
179
|
-
await setDoc(doc(db, `editions/${edition.id}/chapters`, chapter.id), spec);
|
|
180
|
-
};
|
|
181
|
-
export const subdomainIsAvailable = async (subdomain, book) => {
|
|
182
|
-
if (!db)
|
|
183
|
-
throw Error("Not connected to Firebase.");
|
|
184
|
-
const matches = await getDocs(query(collection(db, "books"), where("domain", "==", subdomain)));
|
|
185
|
-
return matches.empty || matches.docs[0].id === book.getRefID();
|
|
186
|
-
};
|
|
187
|
-
export const getBookIDFromBookName = async (subdomain) => {
|
|
188
|
-
if (!db)
|
|
189
|
-
throw Error("Can't find book ID from URL, not connected to Firebase.");
|
|
190
|
-
const matches = await getDocs(query(collection(db, "books"), where("domain", "==", subdomain)));
|
|
191
|
-
if (!matches.empty)
|
|
192
|
-
return matches.docs[0].id;
|
|
193
|
-
throw Error("No book by this name.");
|
|
194
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import Node from "./Node";
|
|
2
|
-
export default class ReferenceNode extends Node {
|
|
3
|
-
readonly citationID: string;
|
|
4
|
-
readonly authors: string;
|
|
5
|
-
readonly year: string;
|
|
6
|
-
readonly title: string;
|
|
7
|
-
readonly source: string;
|
|
8
|
-
readonly url: string;
|
|
9
|
-
readonly summary: string;
|
|
10
|
-
readonly short: boolean;
|
|
11
|
-
constructor(citationID: string, authors?: string, year?: string, title?: string, source?: string, url?: string, summary?: string, short?: boolean);
|
|
12
|
-
getType(): string;
|
|
13
|
-
getChildren(): never[];
|
|
14
|
-
getParentOf(): Node | undefined;
|
|
15
|
-
toText(): string;
|
|
16
|
-
toBookdown(): string;
|
|
17
|
-
toHTML(): string;
|
|
18
|
-
toList(): string[];
|
|
19
|
-
copy(): this;
|
|
20
|
-
withChildReplaced(): undefined;
|
|
21
|
-
withContentInRange(): this | undefined;
|
|
22
|
-
withCitationID(id: string): ReferenceNode;
|
|
23
|
-
withAuthors(authors: string): ReferenceNode;
|
|
24
|
-
withYear(year: string): ReferenceNode;
|
|
25
|
-
withTitle(title: string): ReferenceNode;
|
|
26
|
-
withSource(source: string): ReferenceNode;
|
|
27
|
-
withURL(url: string): ReferenceNode;
|
|
28
|
-
withSummary(summary: string): ReferenceNode;
|
|
29
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import Node from "./Node";
|
|
2
|
-
export default class ReferenceNode extends Node {
|
|
3
|
-
citationID;
|
|
4
|
-
authors;
|
|
5
|
-
year;
|
|
6
|
-
title;
|
|
7
|
-
source;
|
|
8
|
-
url;
|
|
9
|
-
summary;
|
|
10
|
-
short;
|
|
11
|
-
constructor(citationID, authors = "", year = "", title = "", source = "", url = "", summary = "", short = false) {
|
|
12
|
-
super();
|
|
13
|
-
this.citationID = citationID;
|
|
14
|
-
this.authors = authors;
|
|
15
|
-
this.year = year;
|
|
16
|
-
this.title = title;
|
|
17
|
-
this.source = source;
|
|
18
|
-
this.url = url;
|
|
19
|
-
this.summary = summary;
|
|
20
|
-
this.short = short;
|
|
21
|
-
}
|
|
22
|
-
getType() { return "reference"; }
|
|
23
|
-
getChildren() { return []; }
|
|
24
|
-
getParentOf() { return undefined; }
|
|
25
|
-
toText() { return this.authors + " " + this.year + " " + this.title + " " + this.source + (this.summary ? this.summary : ""); }
|
|
26
|
-
toBookdown() { return ""; }
|
|
27
|
-
toHTML() { return ""; }
|
|
28
|
-
toList() {
|
|
29
|
-
const list = [this.authors, this.year, this.title, this.source];
|
|
30
|
-
if (this.url)
|
|
31
|
-
list.push(this.url);
|
|
32
|
-
if (this.summary)
|
|
33
|
-
list.push(this.summary);
|
|
34
|
-
return list;
|
|
35
|
-
}
|
|
36
|
-
copy() {
|
|
37
|
-
return new ReferenceNode(this.citationID, this.authors, this.year, this.title, this.source, this.url, this.summary, this.short);
|
|
38
|
-
}
|
|
39
|
-
withChildReplaced() { return undefined; }
|
|
40
|
-
withContentInRange() { return this.copy(); }
|
|
41
|
-
withCitationID(id) { return new ReferenceNode(id, this.authors, this.year, this.title, this.source, this.url, this.summary, this.short); }
|
|
42
|
-
withAuthors(authors) { return new ReferenceNode(this.citationID, authors, this.year, this.title, this.source, this.url, this.summary, this.short); }
|
|
43
|
-
withYear(year) { return new ReferenceNode(this.citationID, this.authors, year, this.title, this.source, this.url, this.summary, this.short); }
|
|
44
|
-
withTitle(title) { return new ReferenceNode(this.citationID, this.authors, this.year, title, this.source, this.url, this.summary, this.short); }
|
|
45
|
-
withSource(source) { return new ReferenceNode(this.citationID, this.authors, this.year, this.title, source, this.url, this.summary, this.short); }
|
|
46
|
-
withURL(url) { return new ReferenceNode(this.citationID, this.authors, this.year, this.title, this.source, url, this.summary, this.short); }
|
|
47
|
-
withSummary(summary) { return new ReferenceNode(this.citationID, this.authors, this.year, this.title, this.source, this.url, summary, this.short); }
|
|
48
|
-
}
|
package/models/loadEdition.d.ts
DELETED
package/models/loadEdition.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { getBookFromIDOrName } from "./Firestore";
|
|
2
|
-
export default async function loadEdition(bookIDOrName, editionID, latestPublished) {
|
|
3
|
-
const getEditionNumber = editionID === undefined ? undefined : parseInt(editionID);
|
|
4
|
-
const book = await getBookFromIDOrName(bookIDOrName);
|
|
5
|
-
if (book === null)
|
|
6
|
-
return null;
|
|
7
|
-
const unspecifiedEdition = getEditionNumber === undefined || isNaN(getEditionNumber) || !book.isValidEditionNumber(getEditionNumber);
|
|
8
|
-
const edition = unspecifiedEdition ?
|
|
9
|
-
await (latestPublished ? book.getLatestPublishedEdition() : book.getDraftEdition()) :
|
|
10
|
-
await book.getEditionNumber(getEditionNumber);
|
|
11
|
-
return {
|
|
12
|
-
book: book,
|
|
13
|
-
edition: edition,
|
|
14
|
-
latest: unspecifiedEdition
|
|
15
|
-
};
|
|
16
|
-
}
|