bookish-press 0.5.25 → 0.5.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/components/BookPreview.svelte +1 -0
  2. package/dist/components/chapter/Callout.svelte +0 -1
  3. package/dist/components/chapter/Embed.svelte +4 -3
  4. package/dist/components/chapter/ExtendedPrism.d.ts +1 -1
  5. package/dist/components/chapter/Figure.svelte +0 -1
  6. package/dist/components/chapter/Footnote.svelte +1 -0
  7. package/dist/components/chapter/List.svelte +16 -33
  8. package/dist/components/chapter/Paragraph.svelte +7 -2
  9. package/dist/components/chapter/Quote.svelte +6 -6
  10. package/dist/components/controls/DarkToggle.svelte +1 -1
  11. package/dist/components/editor/BookishEditor.svelte +9 -16
  12. package/dist/components/editor/Commands.js +14 -14
  13. package/dist/components/editor/ConfirmButton.svelte +1 -1
  14. package/dist/components/editor/EmbedEditor.svelte +3 -3
  15. package/dist/components/editor/ImageChooser.svelte +6 -26
  16. package/dist/components/editor/ImageThumbnail.svelte +61 -0
  17. package/dist/components/editor/ImageThumbnail.svelte.d.ts +19 -0
  18. package/dist/components/editor/Permissions.svelte +2 -0
  19. package/dist/components/editor/TextEditor.svelte +5 -2
  20. package/dist/components/editor/Toggle.svelte +1 -1
  21. package/dist/components/page/Chapter.svelte +1 -1
  22. package/dist/components/page/DefinitionView.svelte +43 -38
  23. package/dist/components/page/Edition.svelte +11 -4
  24. package/dist/components/page/EditionLoader.svelte +12 -3
  25. package/dist/components/page/Editions.svelte +1 -1
  26. package/dist/components/page/Header.svelte +73 -69
  27. package/dist/components/page/Media.svelte +5 -4
  28. package/dist/components/page/MediaPreview.svelte +8 -2
  29. package/dist/components/page/MediaPreview.svelte.d.ts +1 -0
  30. package/dist/components/page/Outline.svelte +1 -1
  31. package/dist/components/page/Page.svelte +6 -3
  32. package/dist/components/page/Reference.svelte +1 -1
  33. package/dist/components/page/Search.svelte +1 -1
  34. package/dist/components/page/TableOfContents.svelte +3 -6
  35. package/dist/components/page/TableOfContentsRow.svelte +1 -1
  36. package/dist/components/page/ThemeEditor.svelte +1 -1
  37. package/dist/models/CRUD.d.ts +1 -0
  38. package/dist/models/CRUD.js +17 -4
  39. package/dist/models/book/BookMedia.d.ts +3 -0
  40. package/dist/models/book/BookMedia.js +22 -5
  41. package/dist/models/book/Chapter.d.ts +9 -7
  42. package/dist/models/book/Chapter.js +16 -6
  43. package/dist/models/book/Edition.d.ts +6 -1
  44. package/dist/models/book/Edition.js +22 -10
  45. package/dist/models/book/Words.js +0 -1
  46. package/dist/models/chapter/ChapterNode.d.ts +1 -0
  47. package/dist/models/chapter/ChapterNode.js +3 -0
  48. package/dist/models/chapter/DefinitionNode.js +1 -1
  49. package/dist/models/chapter/FormatNode.js +4 -1
  50. package/dist/models/chapter/InlineCodeNode.js +1 -1
  51. package/dist/models/chapter/LinkNode.js +1 -1
  52. package/dist/models/chapter/ListNode.js +1 -1
  53. package/dist/models/chapter/Parser.js +3 -6
  54. package/package.json +20 -18
@@ -39,9 +39,9 @@ export default class Chapter {
39
39
  * The spec may contain the text itself, but it may not, so we require it to be
40
40
  * repeated here to guarantee its provided.
41
41
  */
42
- static fromJSON(spec, text) {
42
+ static fromJSON(spec) {
43
43
  // Copy the spec, filling in defaults as necessary.
44
- return new Chapter(spec.ref, spec.id, spec.title, spec.authors ?? [], spec.image ?? null, spec.numbered === true || spec.numbered === undefined, spec.forthcoming === true, spec.section, spec.text ?? text, spec.uids);
44
+ return new Chapter(spec.ref, spec.id, spec.title, spec.authors ?? [], spec.image ?? null, spec.numbered === true || spec.numbered === undefined, spec.forthcoming === true, spec.section, spec.text ?? null, spec.uids);
45
45
  }
46
46
  toJSON() {
47
47
  // Note that we don't include the chapter text in the payload; that's stored in the chapters subcollection.
@@ -64,6 +64,9 @@ export default class Chapter {
64
64
  getRef() {
65
65
  return this.ref;
66
66
  }
67
+ hasRefID(id) {
68
+ return this.ref !== undefined && this.ref.id === id;
69
+ }
67
70
  withEditors(uids) {
68
71
  return new Chapter(this.ref, this.id, this.title, this.authors, this.image, this.numbered, this.forthcoming, this.section, this.text, uids);
69
72
  }
@@ -144,6 +147,8 @@ export default class Chapter {
144
147
  return new Chapter(this.ref, this.id, this.title, this.authors, image, this.numbered, this.forthcoming, this.section, this.text, this.uids);
145
148
  }
146
149
  getAST(edition) {
150
+ if (this.text === null)
151
+ return undefined;
147
152
  // Compute the cache if necessary
148
153
  if (this._ast === undefined)
149
154
  this._ast = Parser.parseChapter(edition, this.text);
@@ -151,18 +156,23 @@ export default class Chapter {
151
156
  }
152
157
  getWordCount(edition) {
153
158
  if (this._wordCount === undefined)
154
- this._wordCount = this.getAST(edition).toText().split(/\s+/).length;
159
+ this._wordCount = this.getAST(edition)
160
+ ?.toText()
161
+ .split(/\s+/).length;
155
162
  return this._wordCount;
156
163
  }
157
164
  // Utility function
158
165
  getReadingTime(edition) {
159
- return this.isForthcoming()
166
+ const wordCount = this.getWordCount(edition);
167
+ return wordCount === undefined || this.isForthcoming()
160
168
  ? undefined
161
- : Math.max(1, Math.round(this.getWordCount(edition) / 150));
169
+ : Math.max(1, Math.round(wordCount / 150));
162
170
  }
163
171
  getIndex(edition) {
164
172
  if (this._index === undefined) {
165
173
  const ast = this.getAST(edition);
174
+ if (ast === undefined)
175
+ return {};
166
176
  // Build a list of common words
167
177
  let commonWords = new Set();
168
178
  CommonWords.forEach((word) => commonWords.add(word));
@@ -207,6 +217,6 @@ export default class Chapter {
207
217
  return this._index;
208
218
  }
209
219
  toString() {
210
- return `${this.title} by ${this.authors.join(', ')}: ${this.text.substring(0, 32)}}`;
220
+ return `${this.title} by ${this.authors.join(', ')}: ${this.text?.substring(0, 32)}}`;
211
221
  }
212
222
  }
@@ -83,6 +83,7 @@ export default class Edition {
83
83
  withoutRefs(): Edition;
84
84
  withIncrementedEditionNumber(): Edition;
85
85
  withNewChapter(): Edition;
86
+ hasChapterRefID(id: string): boolean;
86
87
  withoutChapter(chapterID: string): Edition;
87
88
  withMovedChapter(chapterID: string, increment: number): Edition;
88
89
  getSymbols(): Record<string, string>;
@@ -107,6 +108,7 @@ export default class Edition {
107
108
  withTheme(theme: Theme | null): Edition;
108
109
  withThemeValue(group: string, name: string, value: string): Edition;
109
110
  getAuthors(): string[];
111
+ getAuthorsText(): string;
110
112
  withAuthors(authors: string[]): Edition;
111
113
  withAuthor(name: string): Edition;
112
114
  withAuthorName(index: number, name: string): Edition;
@@ -130,7 +132,10 @@ export default class Edition {
130
132
  getBookIndex(): Record<string, Set<string>>;
131
133
  getNextChapterID(chapterID: string): string | null;
132
134
  getPreviousChapterID(chapterID: string): string | null;
133
- getEmbeds(): EmbedNode[];
135
+ getEmbeds(): {
136
+ embed: EmbedNode;
137
+ chapterID: string | undefined;
138
+ }[];
134
139
  isLatestEdition(book: Book): boolean;
135
140
  isLatestPublishedEdition(book: Book): boolean;
136
141
  getEditionNumber(): number;
@@ -59,7 +59,7 @@ export default class Edition {
59
59
  static fromJSON(editionRef, spec) {
60
60
  // Copy all of the specification metadata to fields.
61
61
  // Choose suitable defaults if the spec is lacking a field.
62
- return new Edition(spec.bookRef, editionRef, spec.uids, spec.title, spec.authors, spec.number, spec.summary, spec.published, spec.images, spec.description, spec.chapters.map((chap) => Chapter.fromJSON(chap, '')), spec.license, spec.acknowledgements, spec.tags ?? [], spec.sources ?? {}, spec.references ?? {}, spec.symbols ?? {}, spec.glossary ?? {}, spec.theme, spec.base ?? '', spec.active);
62
+ return new Edition(spec.bookRef, editionRef, spec.uids, spec.title, spec.authors, spec.number, spec.summary, spec.published, spec.images, spec.description, spec.chapters.map((chap) => Chapter.fromJSON(chap)), spec.license, spec.acknowledgements, spec.tags ?? [], spec.sources ?? {}, spec.references ?? {}, spec.symbols ?? {}, spec.glossary ?? {}, spec.theme, spec.base, spec.active);
63
63
  }
64
64
  static parseReference(citationID, ref, edition, short = false) {
65
65
  if (typeof ref === 'string')
@@ -99,7 +99,7 @@ export default class Edition {
99
99
  symbols: Object.assign({}, this.symbols),
100
100
  glossary: Object.assign({}, this.glossary),
101
101
  theme: this.theme,
102
- base: this.base,
102
+ base: this.base && this.base.length > 0 ? this.base : null,
103
103
  uids: this.uids.slice(),
104
104
  chapteruids: this.getChapterUIDS(),
105
105
  active: this.active,
@@ -175,15 +175,19 @@ export default class Edition {
175
175
  return new Edition(this.bookRef, this.editionRef, this.uids, this.title, this.authors, this.number, this.summary, this.published, this.images, this.description, chapters, this.license, this.acknowledgements, this.tags, this.sources, this.references, this.symbols, this.glossary, this.theme, this.base, this.active);
176
176
  }
177
177
  withChapterText(text) {
178
- return this.withChapters(this.chapters.map((chapter) => {
178
+ // No need to make a new edition if no chapter was changed.
179
+ let modified = false;
180
+ const newChapters = this.chapters.map((chapter) => {
179
181
  if (chapter.ref === undefined)
180
182
  return chapter;
181
183
  const match = text.find(([ref, text]) => chapter.ref !== undefined &&
182
184
  chapter.ref.id === ref.id &&
183
- chapter.text !== text &&
184
- text !== undefined);
185
+ chapter.text !== text);
186
+ if (match)
187
+ modified = true;
185
188
  return match ? chapter.withText(match[1]) : chapter;
186
- }));
189
+ });
190
+ return modified ? this.withChapters(newChapters) : this;
187
191
  }
188
192
  withRevisedChapter(previous, edited) {
189
193
  const index = this.chapters.indexOf(previous);
@@ -210,6 +214,9 @@ export default class Edition {
210
214
  const newChapter = new Chapter(undefined, `chapter${number}`, 'Untitled Chapter', [], null, true, false, undefined, '', []);
211
215
  return this.withChapters([...this.chapters, newChapter]);
212
216
  }
217
+ hasChapterRefID(id) {
218
+ return this.chapters.some((chapter) => chapter.hasRefID(id));
219
+ }
213
220
  withoutChapter(chapterID) {
214
221
  let index = this.chapters.findIndex((chapter) => chapter.getID() === chapterID);
215
222
  if (index < 0)
@@ -340,6 +347,11 @@ export default class Edition {
340
347
  getAuthors() {
341
348
  return [...this.authors];
342
349
  }
350
+ getAuthorsText() {
351
+ return this.getAuthors()
352
+ .map((author) => Parser.parseFormat(this, author).toText())
353
+ .join(', ');
354
+ }
343
355
  withAuthors(authors) {
344
356
  return new Edition(this.bookRef, this.editionRef, this.uids, this.title, authors, this.number, this.summary, this.published, this.images, this.description, this.chapters, this.license, this.acknowledgements, this.tags, this.sources, this.references, this.symbols, this.glossary, this.theme, this.base, this.active);
345
357
  }
@@ -563,18 +575,18 @@ export default class Edition {
563
575
  if (cover) {
564
576
  let coverNode = Parser.parseEmbed(this, cover);
565
577
  if (coverNode instanceof EmbedNode)
566
- embeds.push(coverNode);
578
+ embeds.push({ embed: coverNode, chapterID: undefined });
567
579
  }
568
580
  // Add the cover and images from each chapter.
569
581
  this.getChapters().forEach((c) => {
570
582
  const image = c.getImage();
571
583
  let cover = image === null ? undefined : Parser.parseEmbed(this, image);
572
584
  if (cover && cover instanceof EmbedNode)
573
- embeds.push(cover);
585
+ embeds.push({ embed: cover, chapterID: c.id });
574
586
  // Get the chapter body's embeds
575
587
  let bodyEmbeds = c?.getAST(this)?.getEmbeds();
576
588
  if (bodyEmbeds)
577
- bodyEmbeds.forEach((embed) => embeds.push(embed));
589
+ bodyEmbeds.forEach((embed) => embeds.push({ embed, chapterID: c.id }));
578
590
  });
579
591
  // Add the back matter covers
580
592
  let backmatter = ['references', 'glossary', 'index', 'search', 'media'];
@@ -583,7 +595,7 @@ export default class Edition {
583
595
  if (img) {
584
596
  let image = Parser.parseEmbed(this, img);
585
597
  if (image instanceof EmbedNode)
586
- embeds.push(image);
598
+ embeds.push({ embed: image, chapterID: id });
587
599
  }
588
600
  });
589
601
  return embeds;
@@ -62,7 +62,6 @@ const CommonWords = [
62
62
  'other',
63
63
  'our',
64
64
  'out',
65
- 'people',
66
65
  'say',
67
66
  'see',
68
67
  'she',
@@ -22,6 +22,7 @@ export default class ChapterNode extends BlocksNode {
22
22
  getEmbeds(): EmbedNode[];
23
23
  getComments(): CommentNode[];
24
24
  getLabels(): LabelNode[];
25
+ getFirstParagraph(): ParagraphNode | undefined;
25
26
  hasLabel(labelID: string): boolean;
26
27
  getCitationNumber(citationID: string): number | null;
27
28
  toText(): string;
@@ -45,6 +45,9 @@ export default class ChapterNode extends BlocksNode {
45
45
  getLabels() {
46
46
  return this.getNodes().filter((n) => n instanceof LabelNode);
47
47
  }
48
+ getFirstParagraph() {
49
+ return this.getBlocks().find((b) => b instanceof ParagraphNode);
50
+ }
48
51
  hasLabel(labelID) {
49
52
  return (this.getLabels().find((label) => label.getMeta() === labelID) !==
50
53
  undefined);
@@ -14,7 +14,7 @@ export default class DefinitionNode extends MetadataNode {
14
14
  return `${this.getText().toHTML()}`;
15
15
  }
16
16
  toBookdown() {
17
- return `~${this.getText().toBookdown()}~${this.getMeta()}`;
17
+ return `~${this.getText().getText()}~${this.getMeta()}`;
18
18
  }
19
19
  copy() {
20
20
  return new DefinitionNode(this.getText(), this.getMeta());
@@ -18,6 +18,9 @@ export default class FormatNode extends Node {
18
18
  const previous = list[position - 1];
19
19
  return !(previous instanceof TextNode && previous.getLength() === 0);
20
20
  });
21
+ // Always ensure an empty text node.
22
+ if (this.#segments.length === 0)
23
+ this.#segments.push(new TextNode());
21
24
  }
22
25
  getType() {
23
26
  return 'formatted';
@@ -149,7 +152,7 @@ export default class FormatNode extends Node {
149
152
  const text = this.getTextNodes();
150
153
  if (text.length === 0)
151
154
  return undefined;
152
- return { node: this.getTextNodes()[0], index: 0 };
155
+ return { node: this.getFirstTextNode(), index: 0 };
153
156
  }
154
157
  getLastCaret() {
155
158
  const text = this.getTextNodes();
@@ -15,7 +15,7 @@ export default class InlineCodeNode extends MetadataNode {
15
15
  }
16
16
  toBookdown() {
17
17
  return ('`' +
18
- this.getText().toBookdown().replace(/`/g, '\\`') +
18
+ this.getText().getText().replace(/`/g, '\\`') +
19
19
  '`' +
20
20
  (this.getMeta() === 'plaintext' ? '' : this.getMeta()));
21
21
  }
@@ -14,7 +14,7 @@ export default class LinkNode extends MetadataNode {
14
14
  return `<a href="${this.getMeta()}">${this.getText().toHTML()}</a>`;
15
15
  }
16
16
  toBookdown() {
17
- return `[${this.getText().toBookdown()}|${this.getMeta()}]`;
17
+ return `[${this.getText().getText()}|${this.getMeta()}]`;
18
18
  }
19
19
  copy() {
20
20
  return new LinkNode(this.getText(), this.getMeta());
@@ -101,7 +101,7 @@ export default class ListNode extends BlockNode {
101
101
  return (format !== undefined &&
102
102
  caret.node.hasAncestor(root, this) &&
103
103
  caret.index === 0 &&
104
- format.getTextNodes()[0] === caret.node);
104
+ format.getFirstTextNode() === caret.node);
105
105
  }
106
106
  getItemContaining(caret) {
107
107
  const match = this.#items.find((n) => n.getParentOf(caret.node) !== undefined);
@@ -739,12 +739,9 @@ export default class Parser {
739
739
  let code = '';
740
740
  while (this.more() && !this.nextIs('`')) {
741
741
  let next = this.read(false);
742
- if (next === '\\') {
743
- if (this.nextIs('`')) {
744
- this.read();
745
- next = '`';
746
- }
747
- }
742
+ // Skip backslash of escaped characters.
743
+ if (next === '\\')
744
+ next = this.read();
748
745
  code = code + next;
749
746
  }
750
747
  // Read the backtick.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bookish-press",
3
3
  "private": false,
4
- "version": "0.5.25",
4
+ "version": "0.5.32",
5
5
  "type": "module",
6
6
  "description": "A platform for reading and writing readable, accessible, beautiful online books.",
7
7
  "license": "MIT",
@@ -22,35 +22,37 @@
22
22
  "//stage": "echo 'switch to the dev project, deploy, relying on Firebase's predeploy hook to run the build script above before release'",
23
23
  "stage": "firebase use dev && firebase deploy",
24
24
  "//release": "echo 'switch to the prod project, deploy, relying on Firebase's predeploy hook to run the build script above before release'",
25
- "release": "firebase use prod && firebase deploy"
25
+ "release": "firebase use prod && firebase deploy",
26
+ "//merge": "merge dev into main, push to remote",
27
+ "merge": "git checkout main && git merge dev && git push origin main && git checkout dev"
26
28
  },
27
29
  "devDependencies": {
28
- "@sveltejs/adapter-static": "^2.0.1",
29
- "@sveltejs/kit": "^1.7.2",
30
- "@sveltejs/package": "^2.0.0",
31
- "@types/prismjs": "^1.26.0",
30
+ "@sveltejs/adapter-static": "^2.0",
31
+ "@sveltejs/kit": "^1.2",
32
+ "@sveltejs/package": "^2.0",
33
+ "@types/prismjs": "^1.26",
32
34
  "@types/smoothscroll-polyfill": "^0.3.1",
33
- "@types/uuid": "^9.0.0",
34
- "prettier": "^2.8.4",
35
- "prettier-plugin-svelte": "^2.9.0",
35
+ "@types/uuid": "^9.0",
36
+ "prettier": "^2.8",
37
+ "prettier-plugin-svelte": "^2.10",
36
38
  "svelte-adapter-firebase": "^0.15.0",
37
- "svelte-check": "^3.0.3",
38
- "svelte-preprocess": "^5.0.1",
39
- "tslib": "^2.5.0",
40
- "typescript": "^4.9.5",
39
+ "svelte-check": "^3.4",
40
+ "svelte-preprocess": "^5.0",
41
+ "tslib": "^2.5",
42
+ "typescript": "^5.1",
41
43
  "vite": "^4.1.2",
42
- "vitest": "^0.28.5"
44
+ "vitest": "^0.29.2"
43
45
  },
44
46
  "dependencies": {
45
47
  "ajv": "^8.12.0",
46
48
  "ajv-formats": "^2.1.1",
47
49
  "firebase": "latest",
48
- "firebase-functions": "^4.2.1",
50
+ "firebase-functions": "^4.4.0",
49
51
  "prismjs": "^1.29.0",
50
52
  "smoothscroll-polyfill": "^0.4.4",
51
- "svelte": "^3.55.1",
52
- "@sveltejs/kit": "^1.7.2",
53
- "uuid": "^9.0.0"
53
+ "svelte": "^3.59",
54
+ "@sveltejs/kit": "^1.2",
55
+ "uuid": "^9.0"
54
56
  },
55
57
  "types": "./dist/index.d.ts",
56
58
  "exports": {