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/models/Firebase.js
CHANGED
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
import { initializeApp } from
|
|
2
|
-
import { connectAuthEmulator, getAuth } from
|
|
3
|
-
import { connectFirestoreEmulator, getFirestore } from
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { initializeApp } from 'firebase/app';
|
|
2
|
+
import { connectAuthEmulator, getAuth } from 'firebase/auth';
|
|
3
|
+
import { connectFirestoreEmulator, getFirestore } from 'firebase/firestore';
|
|
4
|
+
import { connectFunctionsEmulator, getFunctions } from 'firebase/functions';
|
|
5
|
+
import { connectStorageEmulator, getStorage } from 'firebase/storage';
|
|
6
|
+
import { PUBLIC_READER, PUBLIC_CONTEXT, PUBLIC_FIREBASE_API_KEY, PUBLIC_FIREBASE_AUTH_DOMAIN, PUBLIC_FIREBASE_PROJECT_ID, PUBLIC_FIREBASE_STORAGE_BUCKET, PUBLIC_FIREBASE_MESSAGING_SENDER_ID, PUBLIC_FIREBASE_APP_ID, } from '$env/static/public';
|
|
7
|
+
const isReader = PUBLIC_READER === 'true';
|
|
8
|
+
// Some feedback about context
|
|
9
|
+
if (!isReader && PUBLIC_CONTEXT !== 'prod')
|
|
10
|
+
console.log(`*** ${PUBLIC_CONTEXT.toLocaleUpperCase()} ***`);
|
|
6
11
|
// Initialize Firebase using the environment variables provided at build time.
|
|
7
12
|
// Only do this if we have environment variables defined. (We won't in the standalone Reader).
|
|
8
|
-
export const app = isReader
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
export const app = isReader
|
|
14
|
+
? undefined
|
|
15
|
+
: initializeApp({
|
|
16
|
+
apiKey: PUBLIC_FIREBASE_API_KEY,
|
|
17
|
+
authDomain: PUBLIC_FIREBASE_AUTH_DOMAIN,
|
|
18
|
+
projectId: PUBLIC_FIREBASE_PROJECT_ID,
|
|
19
|
+
storageBucket: PUBLIC_FIREBASE_STORAGE_BUCKET,
|
|
20
|
+
messagingSenderId: PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
|
|
21
|
+
appId: PUBLIC_FIREBASE_APP_ID,
|
|
22
|
+
});
|
|
16
23
|
export const auth = isReader ? undefined : getAuth();
|
|
17
24
|
export const db = isReader ? undefined : getFirestore();
|
|
18
25
|
export const storage = isReader ? undefined : getStorage();
|
|
19
|
-
|
|
26
|
+
export const functions = isReader ? undefined : getFunctions();
|
|
27
|
+
if (!isReader && PUBLIC_CONTEXT === 'local') {
|
|
20
28
|
if (db)
|
|
21
29
|
connectFirestoreEmulator(db, 'localhost', 8080);
|
|
22
30
|
if (auth)
|
|
23
|
-
connectAuthEmulator(auth,
|
|
31
|
+
connectAuthEmulator(auth, 'http://localhost:9099');
|
|
24
32
|
if (storage)
|
|
25
|
-
connectStorageEmulator(storage,
|
|
33
|
+
connectStorageEmulator(storage, 'localhost', 9199);
|
|
34
|
+
if (functions)
|
|
35
|
+
connectFunctionsEmulator(functions, 'localhost', 5001);
|
|
26
36
|
}
|
package/models/book/Book.d.ts
CHANGED
|
@@ -1,60 +1,61 @@
|
|
|
1
|
-
import type { DocumentReference } from
|
|
2
|
-
import BookMedia from
|
|
3
|
-
import Edition
|
|
4
|
-
|
|
1
|
+
import type { DocumentReference } from 'firebase/firestore';
|
|
2
|
+
import BookMedia from './BookMedia';
|
|
3
|
+
import type Edition from './Edition';
|
|
4
|
+
/** A replication of edition info */
|
|
5
|
+
export type EditionInfo = {
|
|
5
6
|
ref: DocumentReference;
|
|
6
|
-
time: number;
|
|
7
7
|
summary: string;
|
|
8
|
-
|
|
8
|
+
number: number;
|
|
9
|
+
published: number | null;
|
|
10
|
+
editionuids: string[];
|
|
11
|
+
chapteruids: string[];
|
|
9
12
|
};
|
|
10
|
-
export
|
|
13
|
+
export type BookSpecification = {
|
|
11
14
|
title: string;
|
|
12
15
|
authors: string[];
|
|
13
16
|
description: string;
|
|
14
17
|
cover: string | null;
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
published: boolean;
|
|
19
|
+
editions: EditionInfo[];
|
|
20
|
+
domain: string | null;
|
|
17
21
|
uids: string[];
|
|
22
|
+
readuids: string[];
|
|
18
23
|
};
|
|
19
24
|
export default class Book {
|
|
20
25
|
readonly ref: DocumentReference;
|
|
21
|
-
readonly
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
readonly title: string;
|
|
27
|
+
readonly authors: string[];
|
|
28
|
+
readonly description: string;
|
|
29
|
+
readonly cover: string | null;
|
|
30
|
+
readonly published: boolean;
|
|
31
|
+
readonly editions: EditionInfo[];
|
|
32
|
+
readonly domain: string | null;
|
|
33
|
+
readonly uids: string[];
|
|
28
34
|
media: BookMedia;
|
|
29
|
-
constructor(ref: DocumentReference,
|
|
30
|
-
saveEdits(): void;
|
|
35
|
+
constructor(ref: DocumentReference, title: string, authors: string[], description: string, cover: string | null, editions: EditionInfo[], domain: string | null, uids: string[]);
|
|
31
36
|
getMedia(): BookMedia;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
toObject(): BookSpecification;
|
|
37
|
-
getSubdomain(): string | undefined;
|
|
38
|
-
setSubdomain(domain: string): Promise<void>;
|
|
37
|
+
static fromJSON(ref: DocumentReference, book: BookSpecification): Book;
|
|
38
|
+
toJSON(): BookSpecification;
|
|
39
|
+
getSubdomain(): string | null;
|
|
40
|
+
withSubdomain(domain: string): Book;
|
|
39
41
|
getTitle(): string;
|
|
40
|
-
|
|
42
|
+
withTitle(title: string): Book;
|
|
41
43
|
getDescription(): string;
|
|
42
|
-
|
|
44
|
+
withDescription(description: string): Book;
|
|
43
45
|
getCover(): string | null;
|
|
44
|
-
|
|
46
|
+
withCover(cover: string | null): Book;
|
|
45
47
|
getAuthors(): string[];
|
|
46
|
-
|
|
48
|
+
withAuthors(authors: string[]): Book;
|
|
47
49
|
getRef(): DocumentReference<import("@firebase/firestore").DocumentData>;
|
|
48
50
|
getRefID(): string;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
getEditionNumberID(number: number): string | undefined;
|
|
52
|
+
getLatestPublishedEditionID(): string;
|
|
53
|
+
getLatestEditionID(): string | undefined;
|
|
54
|
+
getEditions(): EditionInfo[];
|
|
55
|
+
getPublishedEditionCount(): number;
|
|
56
|
+
isEditor(uid: string): boolean;
|
|
57
|
+
withEditors(uids: string[]): Book;
|
|
58
|
+
withEditions(revisions: EditionInfo[]): Book;
|
|
59
|
+
withRevisedEdition(previous: Edition, revised: Edition): Book;
|
|
58
60
|
hasPublishedEdition(): boolean;
|
|
59
|
-
updateMetadataFromEdition(edition: Edition): void;
|
|
60
61
|
}
|
package/models/book/Book.js
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
import
|
|
2
|
-
import BookMedia from "./BookMedia";
|
|
3
|
-
import Edition, { BookSaveStatus } from "./Edition";
|
|
1
|
+
import BookMedia from './BookMedia';
|
|
4
2
|
export default class Book {
|
|
5
3
|
ref;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
title;
|
|
5
|
+
authors;
|
|
6
|
+
description;
|
|
7
|
+
cover;
|
|
8
|
+
published;
|
|
9
|
+
editions;
|
|
10
|
+
domain;
|
|
11
|
+
uids;
|
|
12
12
|
media;
|
|
13
|
-
constructor(ref,
|
|
13
|
+
constructor(ref, title, authors, description, cover, editions, domain, uids) {
|
|
14
14
|
this.ref = ref;
|
|
15
|
-
this.
|
|
15
|
+
this.title = title;
|
|
16
|
+
this.authors = authors;
|
|
17
|
+
this.description = description;
|
|
18
|
+
this.cover = cover;
|
|
19
|
+
// The published state is always true if some edition's published flag isn't null.
|
|
20
|
+
this.published = editions.some((edition) => edition.published !== null);
|
|
21
|
+
// We always keep editions in reversed edition number for easy reference.
|
|
22
|
+
this.editions = editions.sort((a, b) => a.number - b.number);
|
|
23
|
+
this.domain = domain;
|
|
24
|
+
this.uids = uids;
|
|
16
25
|
this.media = new BookMedia(this);
|
|
17
26
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// are edits that haven't been saved, try updating the book,
|
|
21
|
-
// and if we succeed, resolve all of the edits, and if we fail,
|
|
22
|
-
// then reject them.
|
|
23
|
-
if (Date.now() - this.lastEdit > 1000 && this.edits.length > 0) {
|
|
24
|
-
// Tell listeners that this book model changed.
|
|
25
|
-
this.notifyListeners(BookSaveStatus.Saving);
|
|
26
|
-
updateBookInFirestore(this)
|
|
27
|
-
.then(() => {
|
|
28
|
-
// Approve the edits.
|
|
29
|
-
this.edits.forEach(edit => edit.resolve());
|
|
30
|
-
this.notifyListeners(BookSaveStatus.Saved);
|
|
31
|
-
})
|
|
32
|
-
.catch(() => {
|
|
33
|
-
// Reject the edits.
|
|
34
|
-
this.edits.forEach(edit => edit.reject());
|
|
35
|
-
this.notifyListeners(BookSaveStatus.Error);
|
|
36
|
-
})
|
|
37
|
-
.finally(() => {
|
|
38
|
-
// Reset the edit queue.
|
|
39
|
-
this.edits = [];
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
getMedia() { return this.media; }
|
|
44
|
-
// Adds a save request to the queue, to be resolved later after a period of
|
|
45
|
-
// inactivity. Returns a promise that will eventually be resolved.
|
|
46
|
-
requestSave() {
|
|
47
|
-
// Tell listeners that this book model changed.
|
|
48
|
-
this.notifyListeners(BookSaveStatus.Changed);
|
|
49
|
-
// Return a promise that will resolve or reject later after this model saves the edits to the database.
|
|
50
|
-
this.lastEdit = Date.now();
|
|
51
|
-
const promise = new Promise((resolve, reject) => {
|
|
52
|
-
this.edits.push({ resolve: resolve, reject: reject });
|
|
53
|
-
});
|
|
54
|
-
return promise;
|
|
55
|
-
}
|
|
56
|
-
addListener(listener) { this.listeners.add(listener); }
|
|
57
|
-
removeListener(listener) { this.listeners.delete(listener); }
|
|
58
|
-
notifyListeners(status) { this.listeners.forEach(listener => listener.call(undefined, status)); }
|
|
59
|
-
toObject() { return this.spec; }
|
|
60
|
-
getSubdomain() { return this.spec.domain; }
|
|
61
|
-
setSubdomain(domain) {
|
|
62
|
-
if (domain.length === 0)
|
|
63
|
-
delete this.spec.domain;
|
|
64
|
-
else
|
|
65
|
-
this.spec.domain = domain;
|
|
66
|
-
return this.requestSave();
|
|
67
|
-
}
|
|
68
|
-
getTitle() { return this.spec.title; }
|
|
69
|
-
setTitle(title) {
|
|
70
|
-
this.spec.title = title;
|
|
71
|
-
return this.requestSave();
|
|
72
|
-
}
|
|
73
|
-
getDescription() { return this.spec.description; }
|
|
74
|
-
setDescription(description) {
|
|
75
|
-
this.spec.description = description;
|
|
76
|
-
return this.requestSave();
|
|
77
|
-
}
|
|
78
|
-
getCover() { return this.spec.cover; }
|
|
79
|
-
setCover(cover) {
|
|
80
|
-
this.spec.cover = cover;
|
|
81
|
-
return this.requestSave();
|
|
82
|
-
}
|
|
83
|
-
getAuthors() { return this.spec.authors; }
|
|
84
|
-
setAuthors(authors) {
|
|
85
|
-
this.spec.authors = authors;
|
|
86
|
-
return this.requestSave();
|
|
87
|
-
}
|
|
88
|
-
getRef() { return this.ref; }
|
|
89
|
-
getRefID() { return this.ref.id; }
|
|
90
|
-
getDraftEdition() {
|
|
91
|
-
return this.spec.revisions.length === 0 ? undefined : loadEditionFromFirestore(this, this.spec.revisions[0].ref.id);
|
|
92
|
-
}
|
|
93
|
-
isValidEditionNumber(edition) {
|
|
94
|
-
return this.getEditionNumber(edition) !== undefined;
|
|
95
|
-
}
|
|
96
|
-
/* Note: editions are numbered 1-n, but stored in reverse chronological order. */
|
|
97
|
-
getEditionNumber(number) {
|
|
98
|
-
return number < 1 || number > this.spec.revisions.length ?
|
|
99
|
-
undefined :
|
|
100
|
-
loadEditionFromFirestore(this, this.spec.revisions[this.spec.revisions.length - number].ref.id);
|
|
101
|
-
}
|
|
102
|
-
getLatestPublishedEdition() {
|
|
103
|
-
const latest = this.getLatestPublishedEditionID();
|
|
104
|
-
return latest === undefined ? undefined : loadEditionFromFirestore(this, latest);
|
|
27
|
+
getMedia() {
|
|
28
|
+
return this.media;
|
|
105
29
|
}
|
|
106
|
-
|
|
107
|
-
return
|
|
30
|
+
static fromJSON(ref, book) {
|
|
31
|
+
return new Book(ref, book.title, book.authors, book.description, book.cover, book.editions, book.domain, book.uids);
|
|
108
32
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
33
|
+
toJSON() {
|
|
34
|
+
const json = {
|
|
35
|
+
title: this.title,
|
|
36
|
+
authors: this.authors,
|
|
37
|
+
description: this.description,
|
|
38
|
+
cover: this.cover,
|
|
39
|
+
published: this.published,
|
|
40
|
+
domain: this.domain,
|
|
41
|
+
editions: this.editions,
|
|
42
|
+
uids: this.uids,
|
|
43
|
+
readuids: Array.from(new Set(this.editions
|
|
44
|
+
.map((edition) => [
|
|
45
|
+
...edition.editionuids,
|
|
46
|
+
...edition.chapteruids,
|
|
47
|
+
])
|
|
48
|
+
.flat())),
|
|
49
|
+
};
|
|
50
|
+
return json;
|
|
113
51
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.spec.revisions[index].summary = summary;
|
|
117
|
-
return this.requestSave();
|
|
118
|
-
}
|
|
52
|
+
getSubdomain() {
|
|
53
|
+
return this.domain;
|
|
119
54
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.spec.revisions[revisionNumber].published = published;
|
|
123
|
-
return this.requestSave();
|
|
124
|
-
}
|
|
55
|
+
withSubdomain(domain) {
|
|
56
|
+
return new Book(this.ref, this.title, this.authors, this.description, this.cover, this.editions, domain.length === 0 ? null : domain, this.uids);
|
|
125
57
|
}
|
|
126
|
-
|
|
127
|
-
return this.
|
|
58
|
+
getTitle() {
|
|
59
|
+
return this.title;
|
|
60
|
+
}
|
|
61
|
+
withTitle(title) {
|
|
62
|
+
return new Book(this.ref, title, this.authors, this.description, this.cover, this.editions, this.domain, this.uids);
|
|
63
|
+
}
|
|
64
|
+
getDescription() {
|
|
65
|
+
return this.description;
|
|
66
|
+
}
|
|
67
|
+
withDescription(description) {
|
|
68
|
+
return new Book(this.ref, this.title, this.authors, description, this.cover, this.editions, this.domain, this.uids);
|
|
69
|
+
}
|
|
70
|
+
getCover() {
|
|
71
|
+
return this.cover;
|
|
72
|
+
}
|
|
73
|
+
withCover(cover) {
|
|
74
|
+
return new Book(this.ref, this.title, this.authors, this.description, cover, this.editions, this.domain, this.uids);
|
|
75
|
+
}
|
|
76
|
+
getAuthors() {
|
|
77
|
+
return this.authors;
|
|
128
78
|
}
|
|
129
|
-
|
|
130
|
-
this.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.
|
|
79
|
+
withAuthors(authors) {
|
|
80
|
+
return new Book(this.ref, this.title, authors, this.description, this.cover, this.editions, this.domain, this.uids);
|
|
81
|
+
}
|
|
82
|
+
getRef() {
|
|
83
|
+
return this.ref;
|
|
84
|
+
}
|
|
85
|
+
getRefID() {
|
|
86
|
+
return this.ref.id;
|
|
87
|
+
}
|
|
88
|
+
getEditionNumberID(number) {
|
|
89
|
+
// Get the ID corresponding to this number.
|
|
90
|
+
const edition = this.editions.find((ed) => ed.number === number);
|
|
91
|
+
return edition ? edition.ref.id : undefined;
|
|
92
|
+
}
|
|
93
|
+
getLatestPublishedEditionID() {
|
|
94
|
+
return this.editions.filter((ed) => ed.published !== null)[0]?.ref.id;
|
|
95
|
+
}
|
|
96
|
+
getLatestEditionID() {
|
|
97
|
+
return this.editions[0]?.ref.id;
|
|
98
|
+
}
|
|
99
|
+
getEditions() {
|
|
100
|
+
return this.editions.slice();
|
|
101
|
+
}
|
|
102
|
+
getPublishedEditionCount() {
|
|
103
|
+
return this.editions.filter((edition) => edition.published).length;
|
|
104
|
+
}
|
|
105
|
+
isEditor(uid) {
|
|
106
|
+
return this.uids.includes(uid);
|
|
107
|
+
}
|
|
108
|
+
withEditors(uids) {
|
|
109
|
+
return new Book(this.ref, this.title, this.authors, this.description, this.cover, this.editions, this.domain, uids);
|
|
110
|
+
}
|
|
111
|
+
withEditions(revisions) {
|
|
112
|
+
return new Book(this.ref, this.title, this.authors, this.description, this.cover, revisions, this.domain, this.uids);
|
|
113
|
+
}
|
|
114
|
+
withRevisedEdition(previous, revised) {
|
|
115
|
+
// Get the new info.
|
|
116
|
+
const info = revised.getInfo();
|
|
117
|
+
if (info === undefined)
|
|
118
|
+
return this;
|
|
119
|
+
// If no previous addition, just add it.
|
|
120
|
+
if (previous === undefined)
|
|
121
|
+
return this.withEditions([...this.editions, info]);
|
|
122
|
+
// Find the corresponding edition.
|
|
123
|
+
const index = this.editions.findIndex((edition) => edition.number === previous.number);
|
|
124
|
+
return index < 0
|
|
125
|
+
? this
|
|
126
|
+
: this.withEditions([
|
|
127
|
+
...this.editions.slice(0, index),
|
|
128
|
+
info,
|
|
129
|
+
...this.editions.slice(index + 1),
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
hasPublishedEdition() {
|
|
133
|
+
return this.editions.some((revision) => revision.published !== null);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { StorageReference } from
|
|
2
|
-
import type Book from
|
|
3
|
-
export
|
|
1
|
+
import type { StorageReference } from 'firebase/storage';
|
|
2
|
+
import type Book from './Book';
|
|
3
|
+
export type Image = {
|
|
4
4
|
url: string;
|
|
5
5
|
ref: StorageReference;
|
|
6
6
|
};
|
package/models/book/BookMedia.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { deleteObject, getDownloadURL, listAll, ref, uploadBytes } from
|
|
1
|
+
import { deleteObject, getDownloadURL, listAll, ref, uploadBytes, } from 'firebase/storage';
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
-
import { storage } from
|
|
3
|
+
import { storage } from '../Firebase';
|
|
4
4
|
export default class BookMedia {
|
|
5
5
|
book;
|
|
6
6
|
_images;
|
|
@@ -12,7 +12,7 @@ export default class BookMedia {
|
|
|
12
12
|
notify(observer) {
|
|
13
13
|
this.observers.add(observer);
|
|
14
14
|
// Notify it right away!
|
|
15
|
-
this.getImages().then(images => observer(images));
|
|
15
|
+
this.getImages().then((images) => observer(images));
|
|
16
16
|
}
|
|
17
17
|
stopNotifying(observer) {
|
|
18
18
|
this.observers.delete(observer);
|
|
@@ -21,13 +21,15 @@ export default class BookMedia {
|
|
|
21
21
|
async getImages() {
|
|
22
22
|
return this._images === undefined ? this.cacheImages() : this._images;
|
|
23
23
|
}
|
|
24
|
-
getImagePath() {
|
|
24
|
+
getImagePath() {
|
|
25
|
+
return `images/${this.book.getRefID()}/`;
|
|
26
|
+
}
|
|
25
27
|
/** Get a listing of all of the images for the book. */
|
|
26
28
|
async cacheImages() {
|
|
27
29
|
if (storage === undefined)
|
|
28
30
|
return [];
|
|
29
31
|
// Find all the prefixes and items.
|
|
30
|
-
this._images = (await this.retrieveImages()).filter(image => image !== undefined);
|
|
32
|
+
this._images = (await this.retrieveImages()).filter((image) => image !== undefined);
|
|
31
33
|
// Notify observers
|
|
32
34
|
for (const observer of this.observers)
|
|
33
35
|
observer(this._images.slice());
|
|
@@ -39,10 +41,12 @@ export default class BookMedia {
|
|
|
39
41
|
// Create a reference under which you want to list
|
|
40
42
|
const listRef = ref(storage, this.getImagePath());
|
|
41
43
|
// Find all the prefixes and items.
|
|
42
|
-
return listAll(listRef)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
return listAll(listRef).then((res) => Promise.all(res.items.map((itemRef) => getDownloadURL(itemRef).then((url) => {
|
|
45
|
+
const image = {
|
|
46
|
+
url: url,
|
|
47
|
+
description: '',
|
|
48
|
+
ref: itemRef,
|
|
49
|
+
};
|
|
46
50
|
if (this._images !== undefined) {
|
|
47
51
|
this._images.push(image);
|
|
48
52
|
}
|
|
@@ -51,9 +55,11 @@ export default class BookMedia {
|
|
|
51
55
|
}
|
|
52
56
|
getThumbnailURL(url, thumbnailRef, error, finished, attempt = 0) {
|
|
53
57
|
getDownloadURL(thumbnailRef)
|
|
54
|
-
.then(thumbnail => finished(url, thumbnail))
|
|
58
|
+
.then((thumbnail) => finished(url, thumbnail))
|
|
55
59
|
// Try again in a bit.
|
|
56
|
-
.catch(() => attempt >
|
|
60
|
+
.catch(() => attempt > 25
|
|
61
|
+
? error("Couldn't get the image URL. Connection issues?")
|
|
62
|
+
: setTimeout(() => this.getThumbnailURL(url, thumbnailRef, error, finished, attempt + 1), 250));
|
|
57
63
|
}
|
|
58
64
|
upload(file, progressHandler, errorHandler, finishedHandler) {
|
|
59
65
|
progressHandler;
|
|
@@ -67,11 +73,11 @@ export default class BookMedia {
|
|
|
67
73
|
uploadBytes(imageRef, file)
|
|
68
74
|
.then((snapshot) => {
|
|
69
75
|
getDownloadURL(snapshot.ref)
|
|
70
|
-
.then(url => {
|
|
76
|
+
.then((url) => {
|
|
71
77
|
// Give some time for the cloud function to create a thumbnail, then try to get it's URL.
|
|
72
78
|
setTimeout(() => this.getThumbnailURL(url, thumbnailRef, errorHandler, finishedHandler), 250);
|
|
73
79
|
})
|
|
74
|
-
.catch(() => errorHandler(
|
|
80
|
+
.catch(() => errorHandler('Unable to get image URL.'));
|
|
75
81
|
})
|
|
76
82
|
.then(() => this.cacheImages());
|
|
77
83
|
// This seems to be broken in Firebase right now. Switched above to a no-feedback approach.
|
|
@@ -83,14 +89,14 @@ export default class BookMedia {
|
|
|
83
89
|
// // https://firebase.google.com/docs/storage/web/handle-errors
|
|
84
90
|
// (error) => {
|
|
85
91
|
// console.error(error);
|
|
86
|
-
// errorHandler(
|
|
92
|
+
// errorHandler(
|
|
87
93
|
// error.code === "storage/unauthorized" ? "Wrong permissions to upload" :
|
|
88
|
-
// error.code === "storage/canceled" ? "Upload canceled" :
|
|
94
|
+
// error.code === "storage/canceled" ? "Upload canceled" :
|
|
89
95
|
// error.code === "storage/quota-exceeded" ? "Storage limit reached" :
|
|
90
96
|
// error.code === "storage/unauthenticated" ? "Log in again to upload" :
|
|
91
97
|
// "Unknown upload error"
|
|
92
98
|
// )
|
|
93
|
-
// },
|
|
99
|
+
// },
|
|
94
100
|
}
|
|
95
101
|
async remove(image) {
|
|
96
102
|
if (storage === undefined)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var BookSaveStatus;
|
|
2
|
+
(function (BookSaveStatus) {
|
|
3
|
+
BookSaveStatus[BookSaveStatus["Changed"] = 0] = "Changed";
|
|
4
|
+
BookSaveStatus[BookSaveStatus["Saving"] = 1] = "Saving";
|
|
5
|
+
BookSaveStatus[BookSaveStatus["Saved"] = 2] = "Saved";
|
|
6
|
+
BookSaveStatus[BookSaveStatus["Error"] = 3] = "Error";
|
|
7
|
+
})(BookSaveStatus || (BookSaveStatus = {}));
|
|
8
|
+
export default BookSaveStatus;
|
package/models/book/Chapter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type ChapterNode from
|
|
2
|
-
import type Edition from
|
|
3
|
-
import type { DocumentReference } from
|
|
4
|
-
export
|
|
1
|
+
import type ChapterNode from '../chapter/ChapterNode';
|
|
2
|
+
import type Edition from './Edition';
|
|
3
|
+
import type { DocumentReference } from 'firebase/firestore';
|
|
4
|
+
export type ChapterSpecification = {
|
|
5
5
|
ref?: DocumentReference;
|
|
6
6
|
id: string;
|
|
7
7
|
title: string;
|
|
@@ -11,60 +11,71 @@ export declare type ChapterSpecification = {
|
|
|
11
11
|
forthcoming: boolean;
|
|
12
12
|
section?: string;
|
|
13
13
|
text?: string;
|
|
14
|
+
uids: string[];
|
|
14
15
|
};
|
|
15
|
-
export
|
|
16
|
+
export type ChapterContent = {
|
|
16
17
|
text: string;
|
|
17
18
|
};
|
|
18
|
-
export
|
|
19
|
+
export type Match = {
|
|
19
20
|
left: string;
|
|
20
21
|
match: string;
|
|
21
22
|
right: string;
|
|
22
23
|
};
|
|
23
24
|
export default class Chapter {
|
|
24
|
-
readonly
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
readonly ref: DocumentReference | undefined;
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly title: string;
|
|
28
|
+
readonly authors: string[];
|
|
29
|
+
readonly image: string | null;
|
|
30
|
+
readonly numbered: boolean;
|
|
31
|
+
readonly forthcoming: boolean;
|
|
32
|
+
readonly section: string | undefined;
|
|
33
|
+
readonly text: string;
|
|
34
|
+
readonly uids: string[];
|
|
35
|
+
_ast: ChapterNode | undefined;
|
|
36
|
+
_index: Record<string, Array<Match>> | undefined;
|
|
37
|
+
_wordCount: number | undefined;
|
|
29
38
|
edits: {
|
|
30
39
|
resolve: Function;
|
|
31
40
|
reject: Function;
|
|
32
41
|
}[];
|
|
33
42
|
lastEdit: number;
|
|
34
43
|
listeners: Set<(text: string) => void>;
|
|
35
|
-
constructor(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
constructor(ref: DocumentReference | undefined, id: string, title: string, authors: string[], image: string | null, numbered: boolean, forthcoming: boolean, section: string | undefined, text: string, uids: string[]);
|
|
45
|
+
/**
|
|
46
|
+
* Convert a chapter spec and it's text into a chapter object.
|
|
47
|
+
* The spec may contain the text itself, but it may not, so we require it to be
|
|
48
|
+
* repeated here to guarantee its provided.
|
|
49
|
+
*/
|
|
50
|
+
static fromJSON(spec: ChapterSpecification, text: string): Chapter;
|
|
51
|
+
toJSON(): ChapterSpecification;
|
|
43
52
|
getRef(): DocumentReference<import("@firebase/firestore").DocumentData> | undefined;
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
withEditors(uids: string[]): Chapter;
|
|
54
|
+
withRef(ref: DocumentReference): Chapter;
|
|
55
|
+
withoutRef(): Chapter;
|
|
56
|
+
getID(): string;
|
|
57
|
+
withChapterID(id: string): Chapter;
|
|
46
58
|
getSection(): string | undefined;
|
|
47
|
-
|
|
59
|
+
withSection(section: string): Chapter;
|
|
48
60
|
isForthcoming(): boolean;
|
|
49
|
-
|
|
61
|
+
asForthcoming(forthcoming: boolean): Chapter;
|
|
50
62
|
isNumbered(): boolean;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
asNumbered(numbered: boolean): Chapter;
|
|
64
|
+
isEditor(uid: string): boolean;
|
|
65
|
+
getText(): string;
|
|
66
|
+
withText(text: string): Chapter;
|
|
67
|
+
withAST(ast: ChapterNode): Chapter;
|
|
56
68
|
getAuthors(): string[];
|
|
57
|
-
|
|
58
|
-
|
|
69
|
+
withAuthor(name: string): Chapter;
|
|
70
|
+
withRenamedAuthor(index: number, name: string): Chapter;
|
|
71
|
+
withoutAuthor(index: number): Chapter;
|
|
59
72
|
getTitle(): string;
|
|
60
|
-
|
|
61
|
-
getPosition(): number | undefined;
|
|
62
|
-
move(increment: number): Promise<void>;
|
|
63
|
-
delete(): Promise<void>;
|
|
73
|
+
withTitle(title: string): Chapter;
|
|
64
74
|
getImage(): string | null;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
getReadingTime(): number | undefined;
|
|
69
|
-
|
|
75
|
+
withImage(image: string | null): Chapter;
|
|
76
|
+
getAST(edition: Edition): ChapterNode;
|
|
77
|
+
getWordCount(edition: Edition): number;
|
|
78
|
+
getReadingTime(edition: Edition): number | undefined;
|
|
79
|
+
getIndex(edition: Edition): Record<string, Match[]>;
|
|
80
|
+
toString(): string;
|
|
70
81
|
}
|